问题描述
我有一个很大的项目,其中很多文本都存储在情节提要和变量中的标签中.我知道如何本地化标签中的文本,但不知道如何本地化字符串变量.您能解释一下还是给该指南提供链接.我正在使用Xcode 6.2版
I have a big project with lots of text stored both in labels in storyboard and variables. I know how to localize text in labels, but have no idea how to localize string variables. Can you explain that or give a link to the guide. I'm using Xcode version 6.2
推荐答案
在代码中,您将NSLocalizedString()
与基本语言一起使用:
In code, you use NSLocalizedString()
with your base language:
NSLocalizedString("This is my text", comment: "Label in mainView")
注释可以保留为空的",但对于翻译者(即使您是您)知道字符串从何而来也很有用.
The comment can be left empty "" but it is useful for the translator (even if this is you) to know where the string comes from.
Xcode在您的项目的语言的子文件夹中自动创建文件Localizable.strings
.该文件包含以下条目:
Xcode automatically creates a file Localizable.strings
in your project in a subfolder for the language. The file contains entries like that:
/* Label in mainView */
"This is my text" = "Dies ist mein Text";
您可以使用自己选择的文本编辑器来翻译该文件中的字符串.
You can translate the strings in that file with a text editor of your choice.
使用翻译的更好方法是在Xcode中选择项目目标,然后从菜单中选择
A better way to work with translations is to select the project target in Xcode, then choose from the menu
编辑器->导出以进行本地化...
这将在您选择的位置创建一个文件夹,其中包含xliff格式的语言文件,即德语:de.xliff
This will create a folder in a location of your choice containing a language file in xliff format, i.e. for german: de.xliff
xliff
是标准化(XML)格式.在简单的文本编辑器中编辑该文件有些困难.我为此使用 iXLIFF .对于Mac而言,这是一个非常小的应用程序,使翻译变得轻而易举.
xliff
is a standardized (XML) format. It is somewhat hard to edit that file in a simple text editor. I use iXLIFF for that. It is a very small application for the Mac and makes translations a breeze.
翻译xliff文件后,转到Xcode
After translating the xliff file go to Xcode
编辑器->导入本地化...
,然后选择xliff文件.当缺少某些内容时,Xcode会告诉您.
and choose the xliff file. Xcode will tell you when something is missing.
这篇关于Swift字符串变量本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!