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"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安果移不动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值