简体   繁体   English

当我编辑我的 string.xml 文件 android kotlin 时,字符串资源 ID 不断变化

[英]String resource ID keep changing when I edit my string.xml file, android kotlin

So I have string.xml files for two languages, english and swahili.所以我有两种语言的 string.xml 文件,英语和斯瓦希里语。 I let my users choose their default languages.我让我的用户选择他们的默认语言。 And everything goes well until when I save the string resource ID for later use when they decide to change the language from the application's settings,but whenever I edit or add another string resource,and update my application, the original string ID's change and the string resource ID's that I saved in the database end up fetching values from different string resource from what my users had selected earlier.一切都很顺利,直到我保存字符串资源 ID 以供以后使用时,他们决定从应用程序的设置中更改语言,但是每当我编辑或添加另一个字符串资源并更新我的应用程序时,原始字符串 ID 的更改和字符串我保存在数据库中的资源 ID 最终会从我的用户之前选择的不同字符串资源中获取值。 How do I overcome this?我该如何克服呢? or stop my string resource ID's from changing every time I add new strings.或在每次添加新字符串时阻止我的字符串资源 ID 更改。

And everything goes well until when I save the string resource ID for later use一切都很顺利,直到我保存字符串资源 ID 以备后用

That is not a good plan.这不是一个好计划。

but whenever I edit or add another string resource,and update my application, the original string ID's change and the string resource ID's that I saved in the database end up fetching values from different string resource from what my users had selected earlier但是每当我编辑或添加另一个字符串资源并更新我的应用程序时,原始字符串 ID 的更改和我保存在数据库中的字符串资源 ID 最终会从我的用户之前选择的不同字符串资源中获取值

That is why this is not a good plan.这就是为什么这不是一个好的计划。 Resource IDs are not designed to be constant from build to build.资源 ID 并非设计为在构建之间保持不变。

How do I overcome this?我该如何克服呢?

Do not store string resource IDs in a file, database, Web service, or similar container.不要将字符串资源 ID 存储在文件、数据库、Web 服务或类似容器中。 Instead, store some identifier that you control that allows you to determine what string resource ID(s) that you should use.相反,存储一些控制的标识符,允许您确定应使用的字符串资源 ID。

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

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