项目作者: kxfeng

项目描述 :
A gradle plugin to migrate Android resources at build time
高级语言: Groovy
项目地址: git://github.com/kxfeng/migrate-android-res.git
创建时间: 2017-07-16T19:58:04Z
项目社区:https://github.com/kxfeng/migrate-android-res

开源协议:Apache License 2.0

下载


migrate-android-res

A gradle plugin to migrate Android resources at build time

Usage

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. }
  5. dependencies {
  6. classpath 'com.github.kxfeng:migrate-android-res:1.1.1'
  7. }
  8. }
  9. apply plugin: 'com.github.kxfeng.migrate-android-res'
  10. migrateAndroidRes {
  11. // this plugin will make some changes (modify and delete files) to your working directory, so you'd
  12. // better enable this after you have saved your working files.
  13. enable = true
  14. // task name (any name you like)
  15. layout_zh_task {
  16. from "layout-zh" // one source folder
  17. to "layout-zh-rCN", "layout-zh-rTW" // multiple destination folders
  18. }
  19. values_zh_task {
  20. from "values-zh"
  21. to "values-zh-rCN", "values-zh-rTW"
  22. }
  23. }

Description

From Android 7.0, the strategy of resolving language resources has changed (document). But for Chinese resources, the strategy is not as described as the document. For Android 7.0+, there are two seperated language define:

Language Resource qualifier
Simplified Chinese (Hans) zh zh_CN zh_SG
Traditional Chinese (Hant) zh-TW zh-HK zh-MO
  • Android 7.0+ test result:
User Settings App Resources Resource Resolution
zhCN#Hans default (en)
zh
zh_TW
Try zh_CN => Fail
Try children of Hans => zh
Use zh
zhHK#Hans default (en)
zh
zh_TW
zh_HK
Try children of Hans => zh
Use zh
zhHK#Hant default (en)
zh
zh_TW
Try zh_HK => Fail
Try children of Hant => zh_TW
Use zh_TW
zhHK#Hant default (en)
zh
Try zh_HK => Fail
Try children of Hant => Fail
Use default
zhTW#Hant default (en)
zh
Try zh_TW => Fail
Try children of Hant => Fail
Use default
  • Android 6.0 test result:
User Settings App Resources Resource Resolution
zh_CN default (en)
zh
zh_TW
Try zh_CN => Fail
Try zh => zh
Use zh
zh_TW default (en)
zh
zh_CN
Try zh_TW => Fail
Try zh => zh
Use zh

So, to support Simplified Chinese and Traditional Chinese in all devices, I suggeste to provide two resources: zh-CN for Hans and zh-TW for Hant.

However, when you build an app, there maybe some resources which are same for both Hans and Hant. So you need to put these resource both in zh-CN and zh-TW folder. Everytime doing a copy job is bored and may lead to mistake.

This plugin is writen to resolve problem above. You can just put resources which are same for Hans and Hant in zh folder, such as values-zh, layout_zh, drawable-xhdpi-zh, when build the project, the plugin can help you migrate resources from zh to zh-CN and zh-TW. There will be no zh folder in the final apk, instead two copies of resources are in zh-CN and zh-TW folders separately.

This plugin can used to migrate any Android resource based on qualifier, not just chinese language qualifier.

License

  1. Copyright 2019 kxfeng
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.