简体   繁体   English

如何为 toast 进行本地化?

[英]How make localization for toasts?

I'm wrote localization for ui texts using我正在使用为 ui 文本编写本地化

String languageToLoad  = "en_EN";
 Locale locale = new Locale(languageToLoad); 
 Locale.setDefault(locale);
 Configuration config = new Configuration();
 config.locale = locale;
 context.getResources().updateConfiguration(config,context.getResources().getDisplayMetrics());

This good working for UI views, but my toasts don't have this.这对 UI 视图很有用,但我的敬酒没有这个。 How fix it?怎么修? Strings was created in strings.xml with Locale qualifier.字符串是在 strings.xml 中使用区域设置限定符创建的。

This is quite easy:这很容易:

String string = getString(R.string.your_string_name);

If the string is saved in the right language folder it will be localised automatically.如果字符串保存在正确的语言文件夹中,它将自动本地化。

Read more here: https://developer.android.com/guide/topics/resources/string-resource#:~:text=android%3Atext%3D%22%40string%2Fhello%22%20%2F%3E&text=String%20string%20%3D%20getString%20(R.,int)%20to%20retrieve%20a%20string .在这里阅读更多: https://developer.android.com/guide/topics/resources/string-resource#:~:text=android%3Atext%3D%22%40string%2Fhello%22%20%2F%3E&text=String %20string%20%3D%20getString%20(R.,int)%20to%20retrieve%20a%20string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM