-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(android): getter/setter for applicationLocales in Android 12 and up #14008
Conversation
feat(android): via app compat delegate get default night mode feat(android): via app compat delegate check if compat vector from resources enabled feat(android): via app compat delegate set compat vector from recourses enabled or not. feat(android): via app compat delegate set application locales. feat(android): via app compat delegate get application locales.
Thanks for the PR! A few remarks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some code suggestions you can add in github with some minor code changes to adjust it to the rest of the SDK. It looks like much because I've added and if around it 😄
Ti.Locale.applicationLocales = "de";
console.log(Ti.Locale.applicationLocales);
as some demo code
android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java
Outdated
Show resolved
Hide resolved
android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java
Outdated
Show resolved
Hide resolved
android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java
Outdated
Show resolved
Hide resolved
android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java
Show resolved
Hide resolved
@AbdullahFaqeir you have to click the |
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
…aleModule.java Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
Done :) |
Co-authored-by: Michael Gangolf <m1ga@users.noreply.github.com>
android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java
Outdated
Show resolved
Hide resolved
It works but it's a bit tricky to use as it will restart the activity. I had an endless loop after I've added two setters below each other. Here is a working demo var currentLang = Ti.App.Properties.getString("lang", "de");
const win = Ti.UI.createWindow({});
const btn = Ti.UI.createButton({title: "switch lang"});
const lbl1 = Ti.UI.createLabel({top: 10,text: currentLang});
const lbl = Ti.UI.createLabel({top: 30,text: L("word")});
win.add([btn, lbl, lbl1]);
btn.addEventListener("click", function() {
currentLang = (currentLang == "de") ? "en" : "de";
Ti.App.Properties.setString("lang", currentLang);
Ti.Locale.applicationLocale = currentLang;
})
win.addEventListener("open", function() {
// is called when you switch the language
//
currentLang = Ti.App.Properties.getString("lang", "de");
console.log(Ti.Locale.applicationLocales)
lbl1.text = currentLang;
lbl.text = L("word");
})
win.open(); app/i18n/de/strings.xml
app/i18n/en/strings.xml
one last step @AbdullahFaqeir :
before: https://github.com/tidev/titanium-sdk/blob/master/apidoc/Titanium/Locale/Locale.yml#L221-L227 Summary something like and this:
and
Summary something like NOTE: |
android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java
Outdated
Show resolved
Hide resolved
Added documentation for applicationLocale and applicationLocales which are only available on Android level 33 and up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Thank you for the work
chore(android): let there be gradle 8.
@AbdullahFaqeir careful: you've pushed the gradle part into this PR. Please revert the last changes. |
Yeah I did that by mistake, I forgot to close this PR, I'll fix it rightaway. |
feat(android): via app compat delegate set application locales.
feat(android): via app compat delegate get application locales.
feat(android): via app compat delegate get default night mode
feat(android): via app compat delegate check if compat vector from resources enabled
feat(android): via app compat delegate set compat vector from recourses enabled or not.
Description:
This PR was raised from an issue appeared on android level 33 and later which caused Ti.Locale.setLanguage() not to work properly, which caused random pages not to be translated unless you recall Ti.Locale.setLanguage() on each page.
See here
Nonetheless, I've ported the rest of static methods from AppCompatDelegate.
edited by Michael: for a test code check #14008 (comment)