ios 是否可以更新本地化故事板的字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15094259/
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-08-30 22:28:15  来源:igfitidea点击:

Is it possible to update a localized storyboard's strings?

iosxcodestringlocalizationstoryboard

提问by GeLB

I localized a part of my application with creating a base.lproj storyboard and 3 string files for it. It was a month ago and after that I added new view controller to app, but this controller's buttons and labels not appear in string files

我通过为它创建一个 base.lproj 故事板和 3 个字符串文件来本地化我的应用程序的一部分。这是一个月前,之后我向应用程序添加了新的视图控制器,但该控制器的按钮和标签未出现在字符串文件中

Is it possible to update this 3 storyboard attached string files or I must add new strings translations programmatically with using NSLocalizableString and Localizable.strings?

是否可以更新这 3 个故事板附加的字符串文件,或者我必须使用 NSLocalizableString 和 Localizable.strings 以编程方式添加新的字符串翻译?

回答by Tha Leang

There are two options:

有两种选择:

Option 1

选项1

Xcode can "reload" the file by converting the file to either an [Interface Builder Cocoa Touch Storyboard]file type or a [Localizable Strings]file type.

Xcode 可以通过将文件转换为[Interface Builder Cocoa Touch Storyboard]文件类型或[Localizable Strings]文件类型来“重新加载”文件。

  1. Select your base storyboard file from the Project Navigator
  2. Find the Localizationsection in the File Inspector
  3. If your file is currently a [Localizable Strings], change it to [Interface Builder Cocoa Touch Storyboard] or vice-versa.
  4. Xcode should have converted your storyboard to the current version, while preserving your old localization efforts. Here you can change the file back to the original file type if you would like.
  1. 从项目导航器中选择您的基本故事板文件
  2. 在文件检查器中找到本地化部分
  3. 如果您的文件当前是 [Localizable Strings],请将其更改为 [Interface Builder Cocoa Touch Storyboard],反之亦然。
  4. Xcode 应该已将您的故事板转换为当前版本,同时保留您旧的本地化工作。如果您愿意,您可以在此处将文件更改回原始文件类型。

Option 2

选项 2

Use ibtool to extract the strings in your storyboard.

使用 ibtool 提取故事板中的字符串。

  1. Open the Terminal application
  2. Locate your Base.lproj directory
  3. Use this line to extract the strings:

    ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings

  4. After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file

  1. 打开终端应用程序
  2. 找到您的 Base.lproj 目录
  3. 使用此行提取字符串:

    ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings

  4. ibtool 将字符串提取到 file_name.strings 后,您可以将其复制并粘贴到您原来的 .strings 文件中

Visit for more info: https://conyac.cc/business/columns/localization_guide_ios

更多信息访问:https: //conyac.cc/business/columns/localization_guide_ios

回答by Jeehut

Check out BartyCrouch, it perfectly solves your problem. Also it is open source, actively maintainedand can be easily installed and integratedwithin your project.

查看BartyCrouch,它完美地解决了您的问题。它也是开源的积极维护,可以轻松安装和集成到您的项目中。



InstallBartyCrouch via Homebrew:

通过Homebrew安装BartyCrouch :

brew install bartycrouch

Alternatively, install it via Mint:

或者,通过Mint安装它:

mint install Flinesoft/BartyCrouch

Incrementally updateyour Storyboards/XIBs Strings files:

逐步更新您的 Storyboards/XIBs Strings 文件:

$ bartycrouch update

This will do exactly what you were looking for.

这将完全符合您的要求。



In order to keepyour Storyboards/XIBs Strings files updated over timeI highly recommend adding a build script (instructions on how to add a build script here):

为了您的 Storyboards/XIBs 字符串文件随时间更新,我强烈建议添加构建脚本(有关如何在此处添加构建脚本的说明):

if which bartycrouch > /dev/null; then
    bartycrouch update -x
    bartycrouch lint -x
else
    echo "warning: BartyCrouch not installed, download it from https://github.com/Flinesoft/BartyCrouch"
fi

In addition to incrementally updating your Storyboards/XIBs Strings files this will also make sure your Localizable.stringsfiles stay updatedwith newly added keys in code using NSLocalizedStringand show warnings for duplicate keys or empty values.

除了逐步更新您的 Storyboards/XIBs 字符串文件之外,这还将确保您的Localizable.strings文件使用代码中新添加的键保持更新NSLocalizedString并显示重复键或空值的警告。

Make sure to checkout BartyCrouch on GitHubor this detailed articlefor additional information.

请务必查看GitHub 上的BartyCrouch或这篇详细的文章以获取更多信息。

回答by Sébastien REMY

You can manually add a key in your localization file. You can find the key object by selecting it on storyboard editor. Let's have a look at Object-IDin the identity inspector. It's look like "nwc-b2-19c"

您可以在本地化文件中手动添加密钥。您可以通过在故事板编辑器中选择它来找到关键对象。让我们看看在Object-ID身份检查器中。它看起来像"nwc-b2-19c"

On your localization update or add translation. For example :

在您的本地化更新或添加翻译。例如 :

"nwc-b2-19c.title" = "Translated title";

回答by Gerd Castan

This one is not for everybody, but it requires no additional tools in the terminal and it's easy for small manual changes. (Do not consider this when you want to automate your process.)

这个并不适合所有人,但它不需要终端中的其他工具,并且很容易进行小的手动更改。(当您想自动化您的流程时,不要考虑这一点。)

Step 0: Storyboard language setup

步骤 0:故事板语言设置

  • Base (with english texts)
  • English (localizable strings file does not exist because the base file is english)
  • other languages (localizable strings files)
  • 基地(含英文文本)
  • 英文(可本地化的字符串文件不存在,因为基本文件是英文的)
  • 其他语言(可本地化的字符串文件)

base configuration

基本配置

This step is done only once.

此步骤仅执行一次。

Now when I add something to the storyboard I do the following

现在,当我向故事板添加内容时,我会执行以下操作

Step 1: add the English localizable strings file

第一步:添加英文本地化字符串文件

Add English

添加英语

just mark the English line item.

只需标记英文行项目。

This creates a completely new english localizable strings file with all the lines

这将创建一个全新的英文本地化字符串文件,其中包含所有行

Step 2: copy the new line items into the other language files

第 2 步:将新行项目复制到其他语言文件中

and translate them

并翻译它们

Step 3: unmark English, remove the corresponding localizable strings file

第三步:取消标注英文,去掉对应的localizable strings文件

the file was only needed to get the new line items

该文件仅用于获取新行项目

This is an easy and fast process, everything is done in the storyboard editor

这是一个简单快捷的过程,一切都在故事板编辑器中完成

Edit:

编辑:

This process works very well with small storyboards. For example, I have a tabs based project and I have a storyboard for each tab.

这个过程非常适用于小故事板。例如,我有一个基于选项卡的项目,每个选项卡都有一个故事板。

Search for "storyboard reference" to find tutorials.

搜索“故事板参考”以查找教程。

Good example: Storyboard reference in Xcode, where should we use it?

很好的例子:Xcode 中的 Storyboard 引用,我们应该在哪里使用它?

So each small storyboard only has a few strings to localize.

所以每个小故事板只有几个字符串需要本地化。

回答by jpl850

Finally, my solution was (rudimentary but effective) copy the previous translations and paste them in the a new file created by unchecking and checking the Localization language box.

最后,我的解决方案是(基本但有效)复制以前的翻译并将它们粘贴到通过取消选中并选中本地化语言框创建的新文件中。

This would be useful in some cases like mine when you have to change only one or two texts.

当您只需要更改一两个文本时,这在像我这样的某些情况下会很有用。

回答by Igor

I think the best way is by using built-in export/import Localizations:

我认为最好的方法是使用内置的导出/导入本地化:

  1. In Project Navigator choose you project folder
  2. Choose Editor > Export For Localization,
  3. All translations left on their places and XCode add missed strings automatically. Additionally, before import, you can edit .xliff in XLIFF Editor (for example, online - http://xliff.brightec.co.uk) and then you don't need to do this in XCode.
  4. then Editor > Import Localizations and choose saved .xliff file.
  1. 在项目导航器中选择您的项目文件夹
  2. 选择编辑器 > 导出本地化,
  3. 所有翻译都留在原地,XCode 会自动添加遗漏的字符串。此外,在导入之前,您可以在 XLIFF 编辑器中编辑 .xliff(例如,在线 - http://xliff.brightec.co.uk),然后您不需要在 XCode 中执行此操作。
  4. 然后编辑器 > 导入本地化并选择保存的 .xliff 文件。

P.S. If you don't want to edit in XLIFF Editor and have skipped step 3, XCode can didn't save new strings. In this case open .xliff in XLIFF Editor, re-save without changes and import new file.

PS 如果您不想在 XLIFF 编辑器中编辑并且跳过了第 3 步,则 XCode 可以不保存新字符串。在这种情况下,在 XLIFF 编辑器中打开 .xliff,重新保存而不更改并导入新文件。

回答by J. Fdez

When you click in your storyboard, Main.storyboard for example... On right side you can see the localization menu (see atached image). If you uncheck and check again a lenguage, the file will be generated again. So I usually copy the content, I generate the file again and then I paste the content that I copied and already been translated.

当您单击故事板时,例如 Main.storyboard... 在右侧,您可以看到本地化菜单(请参见附图)。如果您取消选中并再次检查某个语言,则会再次生成该文件。所以我通常复制内容,我再次生成文件,然后粘贴我复制并已翻译的内容。

This is the way that I use to update the dictionary.

这是我用来更新字典的方式。

enter image description here

在此处输入图片说明

回答by Nik Kov

I got a huge storyboard with a lot of strings there. Two languages base english and another arabic. The task was to add some fields and labels to storyboard and add localization for them without any scripts and NSLocalizableStrings.

我有一个巨大的故事板,里面有很多字符串。两种语言基于英语和另一种阿拉伯语。任务是在情节提要中添加一些字段和标签,并在没有任何脚本和 NSLocalizableStrings 的情况下为它们添加本地化。

For me helped next:

接下来对我有帮助:

First: Ensure, you have git to prevent unexpectable changes.

第一:确保你有 git 来防止意外的变化。

  1. Go to target screen in xcode and press Editor-> Export For Localization.... Save the ar.xlifffile somewhere.
  2. Download XLIFF Edtior.
  3. Open ar.xliff file and make changes.
  4. Import this file in xcode. Done! You have updated storyboard strings file.
  1. 转到 xcode 中的目标屏幕并按Editor-> Export For Localization...。将ar.xliff文件保存在某处。
  2. 下载XLIFF 编辑器
  3. 打开 ar.xliff 文件并进行更改。
  4. 在 xcode 中导入此文件。完毕!您已更新故事板字符串文件。

回答by tilo

There is an appa command line tool from Apple named AppleGlotthat supports incremental localisation. I haven't tried it yet, but it looks exactly like the tool you searched for (some time ago).

一个来自 Apple 的名为AppleGlot的命令行工具应用程序支持增量本地化。我还没有尝试过,但它看起来与您搜索的工具(前段时间)完全一样。

回答by Yoichi Tagaya

Here is a scriptto extract strings from storyboards and xibs, and merge them with existing translations.

这是一个从故事板和 xib 中提取字符串并将它们与现有翻译合并的脚本

To run the script automatically when you build a project, put the script into your project root directory, and add a Run Scriptphase with the following line to a target build phases in your project settings.

要在构建项目时自动运行脚本,请将脚本放入项目根目录,然后在项目设置中的目标构建阶段中添加带有以下行的运行脚本阶段。

./mergegenstrings.py PathToSourceDir

Or you can run the script on Terminal manually when you want to.

或者,您可以根据需要在终端上手动运行脚本。

The script runs ibtoolas Tha Leang answered. It also runs genstringsto extract and merge strings marked with NSLocalizedStringin your source code. The script is based on a script in this post, which merges strings after running genstrings.

脚本在ibtoolTha Leang 回答时运行。它还运行genstrings以提取和合并NSLocalizedString源代码中标记为 的字符串。该脚本基于这篇文章中的一个脚本,它在运行后合并字符串genstrings