且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS应用程序的非英语默认语言?

更新时间:2023-12-04 22:24:40

默认为特定的语言不是你应该努力的。假设居住在法国并流利地说法语的日本用户的手机设置为日语。你的应用程序将默认为德语,尽管它有一个法语翻译;我想这不是你想要的,它当然不是用户想要的。

Defaulting to a particular language is not what you should strive for. Suppose a japanese user living in France and fluently speaking French has his phone set to Japanese. Your App would default to German, despite it having a French translation; I guess that's not what you want and it's certainly not what the user wants.

因此,我建议尊重用户设置的语言优先级。

For this reason I suggest to respect the language prioritization as set by the user.

由于你不想支持英语,而是用英语开发了应用程序,你最容易做的就是摆脱 en.lproj 编译后。这将使应用程序只有您计划支持的语言,并且iPhone将选择最适合用户的语言,如iPhone的默认语言设置。

Since you don't want to support English but have developed the App in English, the easiest thing you can do is to just get rid of en.lproj right after compiling. This will leave the app with only the languages you plan to support, and the iPhone will chose the language best suited for the user, as set in iPhone's defaults.

有一个非常简单的解决方案删除特定的本地化

There is a pretty straightforward solution to deleting a specific localization:

让Xcode使用所有目前的本地化和代码签署之前删除 en.lproj 文件夹和所有本地化的文件的语言都消失了。你可以很容易地通过向目标添加一个Run Script Build阶段,包含这一行代码(它是一个Bash脚本):

Let Xcode build the App with all the present localizations and just before code-signing kicks in delete the en.lproj folder and all localized files for that language are gone. You can easily do this by adding a Run Script build phase to the target, containing this one line of code (it's a Bash Script):

rm -r "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/en.lproj"

代码签名在所有构建阶段完成后总是启动,因此只需在当前阶段结束时进行构建阶段。

Code Signing always kicks in after all build phases have completed, so just put that build phase at the end of your current phases.

注意这会增加构建的时间,因为Xcode会重新创建所有的英语文件,因此您可能想在测试期间禁用此步骤。

Note that this increases the time to build because Xcode recreates all English files, so you might want to disable this step during testing.

我希望这是一个可行的解决方案。

I hope that's a viable solution for you.

关于在不存在适当的本地化的情况下,应用程序必须回到德语

问题是是否是适当的本地化?如果用户的第三个选择是法语(在2种不受支持的语言之后),则此解决方案将使应用返回法语,这是 适当的本地化。

Question is what is an appropriate localization? If the user's third choice is French (after 2 unsupported languages), this solution will make the app fall back to French, which is an appropriate localization. More appropriate than setting the user's fifth choice, German, by hand.

当应用程序启动时会发生什么事情:操作系统会降低用户语言列表,如首选项中设置的那样,直到找到匹配的本地化,并使用这种语言。许多应用程序默认为英语而不是德语的原因很简单,因为英语出现在德语以上的大多数用户语言列表中。系统没有固有的语言偏好。如果您删除英语翻译,只有您想要支持的语言,并且在这些语言中,用户列表中较高的语言。

What happens when an app launches is simple: The OS descends the users language list, as set in Preferences, until it finds a matching localization, and uses this language. The reason many apps default to English and not German is simply because English appears on most user language lists above German. There is no inherent language preference to the system. If you delete the English translation, only the languages you want to support are there, and of these languages the one higher on a user's list is taken.