apache / apache/cordova-android
Locales: setup `resConfigs` in template and update it in project when `defaultlocale` is defined
- Dominant language
- JavaScript
- Stars
- 3.8k
- Forks
- 1.6k
- Avg merge
- 16h 18m
- Merged PRs (30d)
- 11
Description
# Feature Request
## Motivation Behind Feature
`resConfigs` is a property that may be added into the app's `build.gradle`.
To mimic what's done in cordova-ios (see some details in https://github.com/apache/cordova-ios/issues/1222) I suggest to setup `resConfigs`, giving it the value `en`, and then if the `defaultlocale="XX"` attribute is defined onto the `widget` tag in config.xml to update it to a different language.
## Feature Description
`resConfigs` mostly [specifies the supported languages](https://developer.android.com/guide/topics/resources/multilingual-support#specify-the-languages-your-app-supports), and relates to [shrinking and optimizing](https://developer.android.com/studio/build/shrink-code#unused-alt-resources) too.
I think it would be good to set it in the template `build.gradle` [here](https://github.com/apache/cordova-android/blob/master/templates/project/app/build.gradle#L182), so that any resources for other languages are removed at build time.
The base value may be `en` like what is done in cordova-ios ([here](https://github.com/apache/cordova-ios/blob/master/templates/project/__PROJECT_NAME__/__PROJECT_NAME__-Info.plist#L6) and [there](https://github.com/apache/cordova-ios/blob/master/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj#L236)).
With a single language it does not change much things except shrinking and optimizing.
Then it would be necessary to support and apply the `defaultlocale` attribute if defined onto the `widget` tag in _config.xml_ so that a different language can override the hardcoded `en` inherited from the template files.
This `resConfig` is really important to define as soon as multiple languages are pushed to the project, like when using [cordova-plugin-localization-strings](https://github.com/kelvinhokk/cordova-plugin-localization-strings). Indeed without it you often end up with the app language "strangely" resolved by the system: see this really good [blog](https://medium.com/@hectorricardomendez/how-to-get-the-current-locale-in-android-fc12d8be6242).
The _localization-strings_ plugin may support it too soon? through https://github.com/kelvinhokk/cordova-plugin-localization-strings/issues/65.
## Alternatives or Workarounds
Custom script after platform add.
Or should I start a new cordova-plugin to add more defaults like this about locales? (to include this, https://github.com/apache/cordova-ios/issues/1222, https://github.com/kelvinhokk/cordova-plugin-localization-strings/issues/65, and more?)
Contributor guide
Research direction
Start with templates/project/app/build.gradle at the referenced resConfigs location, then trace how the widget's defaultlocale attribute in config.xml is read and applied when a project is created or updated. Done means the template defaults to en and a defined defaultlocale replaces that value; check the existing platform tests around project generation and configuration handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, javascript
- Domain
- build-system, internationalization, localization, mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100