我删除了 Xcode 中的本地化,然后我无法添加任何本地化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12623783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:40:25  来源:igfitidea点击:

I deleted the Localizations in Xcode, then I cannot add any Localizations back

iosxcodelocalization

提问by Stella

I deleted the Localizations of the project from the project's info by mistake. Both the storyboard and the related language were removed.

我错误地从项目信息中删除了项目的本地化。故事板和相关语言都被删除了。

I got back the storyboard from previous file but when I want to add a new Localization, a window popped out and asked me to "Choose files and reference language to create English localization" and there is no resource file at all.

我从以前的文件中取回了故事板,但是当我想添加新的本地化时,弹出一个窗口并要求我“选择文件和参考语言以创建英语本地化”,但根本没有资源文件。

How can I add back the localizations?

如何重新添加本地化?

回答by Cameron Lowell Palmer

Adding back a localization

添加回本地化

When you delete your localizations sometimes you can get that situation where you can't add back any localizations in Xcode. Go to the command-line and create a ISO 639-1 two-letter language abbreviationfolder with the lproj extension somewhere within your project.

当您删除本地化时,有时您会遇到无法在 Xcode 中添加任何本地化的情况。转到命令行并在项目中的某处创建一个带有 lproj 扩展名的ISO 639-1 两字母语言缩写文件夹。

Create an empty language folder

创建一个空的语言文件夹

For example:

例如:

${SRCROOT}/Resources/Translations/nb.lproj

or

或者

${SRCROOT}/Resources/Translations/en.lproj

Re-add language files to project

将语言文件重新添加到项目中

In the folder create an empty file called Localizable.stringsand add this file to your project. Don't add the .lprojfolder, just the contents. Then when you go back into the project file you will see the language under localizations. Now when you have added this, you should see the localization in your project.

在文件夹中创建一个名为的空文件Localizable.strings并将此文件添加到您的项目中。不要添加.lproj文件夹,只添加内容。然后当您返回项目文件时,您将看到本地化下的语言。现在,当您添加它时,您应该会在您的项目中看到本地化。

No checkbox

没有复选框

If the added file, like a storyboard, doesn't have a checkbox next to it indicating that is part of that language localization you might need to round trip them through another language. To do this add a new language in the project. It should prompt you to copy the existing localized files over to the new language. Then delete the broken localization and re-add it.

如果添加的文件(如故事板)旁边没有复选框,表明它是该语言本地化的一部分,您可能需要通过另一种语言来回传递它们。为此,在项目中添加一种新语言。它应该提示您将现有的本地化文件复制到新语言。然后删除损坏的本地化并重新添加。

My Example

我的例子

As a specific example, I added the storyboard in the nb.lproj directory to the project. The Norwegian Bokm?l appears in the project, but the checkbox for the language in the storyboard inspector won't let me add it. I created nb_NO in the project and it prompted me to copy over the storyboard. Then the storyboard had that checkbox checked. I deleted the 'nb' localization and re-added it. Now everything was the way I wanted it.

作为一个具体的例子,我将 nb.lproj 目录中的 storyboard 添加到了项目中。Norwegian Bokm?l 出现在项目中,但故事板检查器中的语言复选框不允许我添加它。我在项目中创建了 nb_NO,它提示我复制故事板。然后故事板选中了那个复选框。我删除了“nb”本地化并重新添加了它。现在一切都如我所愿。

回答by Luká? Mareda

I had to solve same problem, and found one solution:

我不得不解决同样的问题,并找到了一个解决方案:

You need to find in finder your *.xcodeproj file and open it as container (ctrl+click on it and you will see it in context menu)

您需要在 finder 中找到您的 *.xcodeproj 文件并将其作为容器打开(ctrl+单击它,您将在上下文菜单中看到它)

Here you can see project.pbxproj file, open it in Xcode. Its large (but still readable file). (it will be better to make some copy on save spot, before you start)

在这里你可以看到 project.pbxproj 文件,在 Xcode 中打开它。它的大(但仍然可读的文件)。(在开始之前最好在保存点制作一些副本)

Now its the task to add the missing language to this file, and its done.(U can try it on other project with localizations).

现在它的任务是将缺少的语言添加到这个文件中,它完成了。(你可以在其他具有本地化的项目上尝试它)。

There is paragraph you need to add. Search in this file for this /* End PBXSourcesBuildPhase section */(its paragraph right before localization paragraph which is missing) and add something like this after:

有一段你需要添加。在这个文件中搜索这个/* End PBXSourcesBuildPhase section */(它在缺少本地化段落之前的段落)并在之后添加如下内容:

/* Begin PBXVariantGroup section */
        27548D921611B0BE008EA1CD /* Localizable.strings */ = {
            isa = PBXVariantGroup;
            children = (
                27548D941611B0BE008EA1CD /* en */,
            );
            name = Localizable.strings;
            path = ../Code;
            sourceTree = "<group>";
        };
/* End PBXVariantGroup section */

You have to do some changes first. Look at the long number 27548D921611B0BE008EA1CD, its ID of the localization file (or some xib file, or other localizable file...), if you dont have any in the procject, just add some Localizable.string file to the project, reopen(or refresh) this project.pbxpro, and find this Localizable.stringyou should find something like this:

你必须先做一些改变。查看27548D921611B0BE008EA1CD本地化文件(或一些xib文件,或其他可本地化文件...)的长号,其ID,如果项目中没有,只需将一些Localizable.string文件添加到项目中,重新打开(或刷新)这个project.pbxpro,找到这个Localizable.string你应该会找到这样的东西:

275490591611B0BE008EA1CD /* Localizable.strings in Resources */

275490591611B0BE008EA1CD /* Localizable.strings in Resources */

and this is it what you need to replace in localization paragraph

这就是您需要在本地化段落中替换的内容

also you need to do right settings on path parametr and sourceTree. This twos are readable in fileinspector in xcode.

您还需要对路径参数和源树进行正确的设置。这两个在 xcode 的文件检查器中是可读的。

The "sourceTree" param is Location - mostly its relative to group so sourceTree = "<group>";

“sourceTree”参数是位置 - 主要是它相对于组 sourceTree = "<group>";

The path is path relative from the group to the file (if you dont know, try to make some localization files in different project and look at project.pbxpro, what all this works)

路径是从组到文件的相对路径(如果你不知道,尝试在不同的项目中制作一些本地化文件并查看project.pbxpro,这一切都有效)

After this you can save project.pbxpro, and you should see in xcode info section "en" localization and you can add more localizations and all other localization stuff.

在此之后,您可以保存 project.pbxpro,您应该在 xcode 信息部分中看到“en”本地化,您可以添加更多本地化和所有其他本地化内容。

回答by oabarca

In xcode 6, do the following:

在 xcode 6 中,执行以下操作:

  1. With the command line, create the following directory/file structure somewhere outside your project directory:

    • /en.lproj/InfoPlist.strings

    • /en.lproj/Localizable.strings

  2. In Xcode, open your project and choose File>Add Files to ProjectName to add the recently created en.lproj directory.

  3. After that, you will see English in the Localizations list.
  1. 使用命令行,在项目目录之外的某处创建以下目录/文件结构:

    • /en.lproj/InfoPlist.strings

    • /en.lproj/Localizable.strings

  2. 在 Xcode 中,打开您的项目并选择 File>Add Files to ProjectName 以添加最近创建的 en.lproj 目录。

  3. 之后,您将在本地化列表中看到英语。

回答by elia

I've followed a similar approach of @user2070775 reply.

我遵循了@user2070775 回复的类似方法。

Firstyl when you delete Storyboardand Launchscreento use your own creation or code programmatically, on Localization you might get similar following empty screen.

首先,当您删除StoryboardLaunchscreen以编程方式使用您自己的创建或代码时,在本地化上,您可能会看到类似的空白屏幕。

enter image description here

在此处输入图片说明

Then firstly you should know the language code for example to use Frenchlocalization its fretc

那么首先你应该知道语言代码,例如使用法语本地化它的fr

With project folder in the Project Navigator you must add New Group -> {LANGUAGE_CODE}.lproj. And then you should add New File -> Strings File -> Localizable.strings. In the @user2070775 answer, also InfoPlist.stringsfile has added so I added too for now.

对于项目导航器中的项目文件夹,您必须添加New Group -> {LANGUAGE_CODE}.lproj. 然后你应该添加New File -> Strings File -> Localizable.strings. 在@user2070775 的回答中,还InfoPlist.strings添加了文件,所以我现在也添加了。

In the Localizable.strings file you can add <KEY> = <VALUE>pairs for string to localizated.

在 Localizable.strings 文件中,您可以添加<KEY> = <VALUE>字符串对以进行本地化。

Our pair is "this-is-key" = "and-this-is-value-for-spesific-language-on-localizable-string";for now.

我们的一对是"this-is-key" = "and-this-is-value-for-spesific-language-on-localizable-string";现在。

HINT: In key-value pair, when I did not put the semicolon, the XCode gives error for this situation.

提示:在键值对中,当我没有放置分号时,XCode 会针对这种情况给出错误。

Until now, the following project scheme, must the result of you have.

到现在为止,下面的工程方案,一定是你有的结果。

enter image description here

在此处输入图片说明

enter image description hereAdditionally, when you looked at the Project -> Info -> Localizationsthe Frenchor etc. language must be added like in the following image.

在此处输入图片说明此外,当您查看Project -> Info -> LocalizationstheFrench或 etc. 时,必须添加如下图所示的语言。

TESTING

测试

Basically you can get the results of the what've you doneenter image description here

基本上你可以得到你所做的结果在此处输入图片说明

The remaining part can be set from the Simulator. You must change the simulator language, for this answer the correct one is French.

其余部分可以从模拟器设置。您必须更改模拟器语言,对于此答案,正确的语言是法语。

Go to Settings -> General -> Language & Region -> Frenchand run the project again.

转到Settings -> General -> Language & Region -> French并再次运行该项目。

回答by karasu99

This is an old topic, but after having this issue, and then trying the solution (and having it not work exactly), I thought I'd give details on what DID work.

这是一个古老的话题,但在遇到这个问题,然后尝试解决方案(并使其无法正常工作)之后,我想我会详细说明 DID 的工作原理。

Like the original poster, I accidentally deleted all of my localizations and was given no obvious recourse in Xcode-- in the project settings under Info it simply said 'this project has not been localized', and when I clicked on the plus button beneath, a blank list of resource files was presented.

就像原来的海报一样,我不小心删除了我所有的本地化,并且在 Xcode 中没有明显的追索权——在信息下的项目设置中,它只是说“这个项目没有被本地化”,当我点击下面的加号按钮时,提供了一个空白的资源文件列表。

I followed @Cameron's guide but found that language folders with Localizable.strings files were already present in Finder, but weren't being acknowledged by Xcode. I couldn't decide how to proceed, but I happened to see an unrelated comment about adding files to Xcode, so I tried adding the existing en.lproj folder and its Localizable.strings file.

我按照@Cameron 的指南进行操作,但发现 Finder 中已经存在带有 Localizable.strings 文件的语言文件夹,但 Xcode 没有确认。我无法决定如何继续,但我碰巧看到一条关于向 Xcode 添加文件的无关评论,因此我尝试添加现有的 en.lproj 文件夹及其 Localizable.strings 文件。

This worked, and the listing for English as the development language appeared under Info as well.

这行得通,并且英语作为开发语言的列表也出现在信息下。

Hopefully this will help anyone who experiences the same problem!

希望这能帮助任何遇到同样问题的人!

回答by Jeba Moses

Simply create a Folder "Base.lproj" in finder and paste the Xib you want to localize inside it, and add this folder to your project. Now you can able to add other languages without issue.

只需在 finder 中创建一个文件夹“Base.lproj”并将您想要本地化的 Xib 粘贴到其中,然后将此文件夹添加到您的项目中。现在您可以毫无问题地添加其他语言。