如何在iOS信息中本地化字符串。plist文件?

时间:2023-02-05 14:06:08

As you might know the iOS 8 requires NSLocationWhenInUseUsageDescription key for using user's location. I have added this key and some general information into my info plist. 如何在iOS信息中本地化字符串。plist文件?

您可能知道,iOS 8需要NSLocationWhenInUseUsageDescription键来使用用户的位置。我已经在我的信息列表中添加了这个键和一些一般的信息。

How can I use translation string inside the plist file ?

如何在plist文件中使用翻译字符串?

-- Update --

——更新

I already have a Localizable string. I'm just wondering that can I use something like NSLocalizedString(MYSTRING,nil) inside the plist string. I know that I can create multiple file of info.plist for localisation but I was wondering there might be an easier way.

我已经有了一个可本地化的字符串。我想知道我能不能在plist字符串中使用NSLocalizedString(MYSTRING,nil)之类的东西。我知道我可以创建多个信息文件。关于本地化的plist,但我想知道可能会有更简单的方法。

7 个解决方案

#1


327  

You should use InfoPlist.strings file to localize values of Info.plist. To do this, go to File->New->File, choose Strings File under Resource tab of iOS, name it InfoPlist, and create. Open and insert the Info.plist values you want to localize like:

您应该使用InfoPlist。字符串文件以本地化Info.plist的值。为此,转到File->New->File,在iOS的Resource选项卡下选择Strings File,命名为InfoPlist,并创建。打开并插入信息。要本地化的plist值如下:

"NSLocationWhenInUseUsageDescription" = "Description of this";

Now you can localize InfoPlist.strings file with translations. Good Luck!

现在可以本地化InfoPlist。字符串文件翻译。好运!

EDIT:

编辑:

select the localization options, or enable localization if needed,

选择本地化选项,或在需要时启用本地化,

如何在iOS信息中本地化字符串。plist文件?

you should be able to see the file also on the left side editor.

您应该能够看到文件也在左边编辑器。

如何在iOS信息中本地化字符串。plist文件?

EDIT:

编辑:

Here is the official documentation for Info.plist keys localization.

这是信息的官方文档。plist键定位。

#2


21  

All the above did not work for me (XCode 7.3) so I read Apple reference on how to do, and it is much simpler than described above. According to Apple:

以上所有这些对我都不起作用(XCode 7.3),所以我阅读了苹果关于如何做的参考资料,它比上面描述的要简单得多。根据苹果公司:

Localized values are not stored in the Info.plist file itself. Instead, you store the values for a particular localization in a strings file with the name InfoPlist.strings. You place this file in the same language-specific project directory that you use to store other resources for the same localization.

本地化值不存储在Info中。plist文件本身。相反,您将特定本地化的值存储在一个名为infoplist .string的字符串文件中。您将该文件放置在您用于存储相同本地化的其他资源的特定于语言的项目目录中。

Accordingly, I created a string file named InfoPlist.strings and placed it in the xx.lproj folder of the "xx" language (and added it to the project using File->Add Files to ...). That's it. No need for the key "Localized resources can be mixed" = YES, and no need for InfoPlist.strings in base.lproj or en.lproj.

因此,我创建了一个名为InfoPlist的字符串文件。字符串并将其放在xx中。“xx”语言的lproj文件夹(并使用File->添加文件到…)。就是这样。不需要关键的“本地化资源可以混合”= YES,也不需要InfoPlist。字符串在基地。lproj或en.lproj。

The application uses the Info.plist key-value as the default value if it can not find a key in the language specific file. Thus, I put my English value in the Info.plist file and the translated one in the language specific file, tested and everything works.

应用程序使用信息。如果在特定语言的文件中找不到键值,plist将键值作为默认值。因此,我把我的英语价值放在信息中。plist文件和翻译文件在语言特定的文件,测试和一切工作。

In particular, there is no need to localize the InfoPlist.strings (which creates a version of the file in the base.lproj, en.lroj, and xx.lproj), and in my case going that way did not work.

特别是,不需要本地化InfoPlist。字符串(在基中创建文件的版本)。lproj,en。lroj和xx.lproj,在我的情况下,这样做没用。

#3


12  

If something is not working make sure you added:

如果有什么不顺利,确保你补充了:

"Localized resources can be mixed" = YES

“本地化资源可以混合使用”= YES

into the info.plist. In my case the InfoPlist.strings files were just ignored.

info.plist。我的情况是信息专家。字符串文件被忽略。

#4


6  

I would highly recommend reading Apple's guides, and viewing the WWDC resources listed here: Internationalization and Localization Topics

我强烈建议您阅读苹果的指南,并查看这里列出的WWDC资源:国际化和本地化主题

To specifically answer your question, when you add a new language to your project如何在iOS信息中本地化字符串。plist文件?, you get an opportunity to choose what InfoPlist files to include (if you have multiple targets, you'll have multiple Info plist files). All you need to do to get the following screen is hit the + under Localizations and choose a new language to add support for. 如何在iOS信息中本地化字符串。plist文件?

为了明确回答您的问题,当您在项目中添加一种新语言时,您将获得一个机会来选择要包含哪些InfoPlist文件(如果您有多个目标,您将有多个Info plist文件)。要得到下面的屏幕,您需要做的就是点击本地化下面的+,并选择一种新的语言来添加对它的支持。

Once you've added, it will create the necessary string files in the appropriate lproj directories for the given language.

添加之后,它将在给定语言的适当lproj目录中创建必要的字符串文件。

--EDIT--

——编辑

Just to be clear, iOS will swap out the string for your Plist file based upon the user's currently selected language using the plist entry's key as the key in the localized strings file.

明确一点,iOS将根据用户当前选择的语言,使用Plist条目的键作为本地化字符串文件中的键,为您的Plist文件交换字符串。

#5


3  

As RGML say, you can create an InfoPlist.strings, localize it then add your key and the value like this: "NSLocationWhenInUseUsageDescription" = "Help To locate me!";

正如RGML所说,您可以创建一个信息列表。字符串,本地化它,然后添加你的键和值如下:“nslocationwhen inusagedescription”=“帮助找到我!”

It will add the key to your info.plist for the specified language.

它会在你的信息中添加密钥。指定语言的plist。

#6


1  

For anyone experiencing the problem of the info.plist not being included when trying to add localizations, like in Xcode 9.

对于任何遇到信息问题的人。plist在尝试添加本地化时不包含,如在Xcode 9中。

You need make the info.plist localiazble by going into it and clicking on the localize button in the file inspector, as shown below.

你需要了解信息。plist localiazble通过进入它并点击文件检查器中的localize按钮,如下所示。

The info.plist will then be included in the file resources for when you go to add new Localizations.

info。然后,当您添加新的本地化时,plist将包含在文件资源中。

如何在iOS信息中本地化字符串。plist文件?

#7


0  

In my case everything was set up correctly but still the InfoPlist.strings file was not found.

在我的情况下,所有的设置都是正确的,但仍然是信息列表。未找到字符串文件。

The only thing that really worked was, to remove and add the InfoPlist.strings files again to the project.

唯一起作用的是,删除和添加信息列表。strings文件再次提交到项目。

#1


327  

You should use InfoPlist.strings file to localize values of Info.plist. To do this, go to File->New->File, choose Strings File under Resource tab of iOS, name it InfoPlist, and create. Open and insert the Info.plist values you want to localize like:

您应该使用InfoPlist。字符串文件以本地化Info.plist的值。为此,转到File->New->File,在iOS的Resource选项卡下选择Strings File,命名为InfoPlist,并创建。打开并插入信息。要本地化的plist值如下:

"NSLocationWhenInUseUsageDescription" = "Description of this";

Now you can localize InfoPlist.strings file with translations. Good Luck!

现在可以本地化InfoPlist。字符串文件翻译。好运!

EDIT:

编辑:

select the localization options, or enable localization if needed,

选择本地化选项,或在需要时启用本地化,

如何在iOS信息中本地化字符串。plist文件?

you should be able to see the file also on the left side editor.

您应该能够看到文件也在左边编辑器。

如何在iOS信息中本地化字符串。plist文件?

EDIT:

编辑:

Here is the official documentation for Info.plist keys localization.

这是信息的官方文档。plist键定位。

#2


21  

All the above did not work for me (XCode 7.3) so I read Apple reference on how to do, and it is much simpler than described above. According to Apple:

以上所有这些对我都不起作用(XCode 7.3),所以我阅读了苹果关于如何做的参考资料,它比上面描述的要简单得多。根据苹果公司:

Localized values are not stored in the Info.plist file itself. Instead, you store the values for a particular localization in a strings file with the name InfoPlist.strings. You place this file in the same language-specific project directory that you use to store other resources for the same localization.

本地化值不存储在Info中。plist文件本身。相反,您将特定本地化的值存储在一个名为infoplist .string的字符串文件中。您将该文件放置在您用于存储相同本地化的其他资源的特定于语言的项目目录中。

Accordingly, I created a string file named InfoPlist.strings and placed it in the xx.lproj folder of the "xx" language (and added it to the project using File->Add Files to ...). That's it. No need for the key "Localized resources can be mixed" = YES, and no need for InfoPlist.strings in base.lproj or en.lproj.

因此,我创建了一个名为InfoPlist的字符串文件。字符串并将其放在xx中。“xx”语言的lproj文件夹(并使用File->添加文件到…)。就是这样。不需要关键的“本地化资源可以混合”= YES,也不需要InfoPlist。字符串在基地。lproj或en.lproj。

The application uses the Info.plist key-value as the default value if it can not find a key in the language specific file. Thus, I put my English value in the Info.plist file and the translated one in the language specific file, tested and everything works.

应用程序使用信息。如果在特定语言的文件中找不到键值,plist将键值作为默认值。因此,我把我的英语价值放在信息中。plist文件和翻译文件在语言特定的文件,测试和一切工作。

In particular, there is no need to localize the InfoPlist.strings (which creates a version of the file in the base.lproj, en.lroj, and xx.lproj), and in my case going that way did not work.

特别是,不需要本地化InfoPlist。字符串(在基中创建文件的版本)。lproj,en。lroj和xx.lproj,在我的情况下,这样做没用。

#3


12  

If something is not working make sure you added:

如果有什么不顺利,确保你补充了:

"Localized resources can be mixed" = YES

“本地化资源可以混合使用”= YES

into the info.plist. In my case the InfoPlist.strings files were just ignored.

info.plist。我的情况是信息专家。字符串文件被忽略。

#4


6  

I would highly recommend reading Apple's guides, and viewing the WWDC resources listed here: Internationalization and Localization Topics

我强烈建议您阅读苹果的指南,并查看这里列出的WWDC资源:国际化和本地化主题

To specifically answer your question, when you add a new language to your project如何在iOS信息中本地化字符串。plist文件?, you get an opportunity to choose what InfoPlist files to include (if you have multiple targets, you'll have multiple Info plist files). All you need to do to get the following screen is hit the + under Localizations and choose a new language to add support for. 如何在iOS信息中本地化字符串。plist文件?

为了明确回答您的问题,当您在项目中添加一种新语言时,您将获得一个机会来选择要包含哪些InfoPlist文件(如果您有多个目标,您将有多个Info plist文件)。要得到下面的屏幕,您需要做的就是点击本地化下面的+,并选择一种新的语言来添加对它的支持。

Once you've added, it will create the necessary string files in the appropriate lproj directories for the given language.

添加之后,它将在给定语言的适当lproj目录中创建必要的字符串文件。

--EDIT--

——编辑

Just to be clear, iOS will swap out the string for your Plist file based upon the user's currently selected language using the plist entry's key as the key in the localized strings file.

明确一点,iOS将根据用户当前选择的语言,使用Plist条目的键作为本地化字符串文件中的键,为您的Plist文件交换字符串。

#5


3  

As RGML say, you can create an InfoPlist.strings, localize it then add your key and the value like this: "NSLocationWhenInUseUsageDescription" = "Help To locate me!";

正如RGML所说,您可以创建一个信息列表。字符串,本地化它,然后添加你的键和值如下:“nslocationwhen inusagedescription”=“帮助找到我!”

It will add the key to your info.plist for the specified language.

它会在你的信息中添加密钥。指定语言的plist。

#6


1  

For anyone experiencing the problem of the info.plist not being included when trying to add localizations, like in Xcode 9.

对于任何遇到信息问题的人。plist在尝试添加本地化时不包含,如在Xcode 9中。

You need make the info.plist localiazble by going into it and clicking on the localize button in the file inspector, as shown below.

你需要了解信息。plist localiazble通过进入它并点击文件检查器中的localize按钮,如下所示。

The info.plist will then be included in the file resources for when you go to add new Localizations.

info。然后,当您添加新的本地化时,plist将包含在文件资源中。

如何在iOS信息中本地化字符串。plist文件?

#7


0  

In my case everything was set up correctly but still the InfoPlist.strings file was not found.

在我的情况下,所有的设置都是正确的,但仍然是信息列表。未找到字符串文件。

The only thing that really worked was, to remove and add the InfoPlist.strings files again to the project.

唯一起作用的是,删除和添加信息列表。strings文件再次提交到项目。