lingver 多语言处理工具

Posted 安果移不动

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lingver 多语言处理工具相关的知识,希望对你有一定的参考价值。

ingver is a library to manage your application locale and language.

Once you set a desired locale, Lingver will enforce your application to provide correctly localized data via Resources class.

The library contains an implementation of the approach described in the following blogpost.

Setup

The setup is pretty simple:

  1. Initialize the library in Application.onCreate:
Lingver.init(context, defaultLanguage)

See the sample app for more customization options.

  1. Change a locale, for instance, from your setting screen:
文档地址:https://github.com/yariksoffice/lingver
Lingver.getInstance().setLocale(context, language)

Note that you need to update all already fetched locale-based data manually. Lingver is not responsible for that.

Follow the system locale

You can configure Lingver to follow the system locale whenever it changes:

 Lingver.getInstance().setFollowSystemLocale(context)

Note that any call to setLocale() stops following the system locale and resets isFollowingSystemLocale() setting.

WebView

Starting from android N, there is a weird side effect while using a WebView in your application. For unknown reasons, the very first creation of it (either programmatically or via inflation) resets an application locale to the system default. Obviously, this is not what we expect to happen. Moreover, it's not going to be fixed anytime in the future according to the issuetracker. That's why we should somehow deal with it on our own.

There are plenty of ways how we can fix that, but the idea stays always the same. You have to set back the desired locale after the first usage of a WebView. For instance, you can even programmatically create a fake WebView and immediately set a locale back which prevents this side effect from happening in the future. See an example of implementation in the sample app.

App Bundles

While using an app bundle, a user’s device only downloads string resources that match the one or more languages currently selected in the device’s settings. Refer to this page if you want to change this behavior and have access to additional language resources.

Download

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation "com.github.YarikSOffice:lingver:1.3.0"
}

以上是关于lingver 多语言处理工具的主要内容,如果未能解决你的问题,请参考以下文章

游戏开发中的多语言处理

在WinForm应用程序中快速实现多语言的处理--开发框架模块的整合

从 .cs 部分代码访问多语言资源

Guarding:开源的多语言架构守护工具

Guarding:开源的多语言架构守护工具

Android通过代码实现多语言切换createConfigurationContextattachBaseContextgetResourcesupdateConfiguration