问题描述
我搜索了 Google 和 StackOverflow ,并且仍然没有明确的答案,这是一个简单而自动的方式,但这里是场景:
I have searched Google and StackOverflow and still have no clear answer on an easy and automated way of doing this but here is the scenario:
- 我有一个应用程序,其中1000个字符串已本地化为en,fr,de,es,it。
- 我建立了一个新的功能,使10个明显新的
NSLocalizedString()
键。 - 我只想将这10个新字符串附加到文件的末尾:
- en.lproj / Localizable.strings
- fr.lproj / Localizable.strings
- es.lproj / Localizable.strings
- de.lproj / Localizable.strings
- it.lproj / Localizable.strings
- I have an app with 1000 strings localized into en, fr, de, es, it.
- I build a new feature that makes 10 distinctly new
NSLocalizedString()
keys. - I just want those 10 new strings appended onto the ends of the files:
- en.lproj/Localizable.strings
- fr.lproj/Localizable.strings
- es.lproj/Localizable.strings
- de.lproj/Localizable.strings
- it.lproj/Localizable.strings
genstrings
将检索所有1010不同的字串。这是一个痛苦,因为每次我做更新时我都需要大海捞针找到那10个字符串。
genstrings
will retrieve all 1010 distinct strings. This is a pain since I'll need to "needle in a haystack" find those 10 strings every time I do an update.
更新19-SEP- 2014年 - XCode 6 - Apple终于发布了对XLIFF导出和导入.strings文件的支持
UPDATE 19-SEP-2014 -- XCode 6 - Apple has finally released support for XLIFF export and import of your .strings filesWhats new in XCode 6? Localisation
Linguan(v1.1.3)虽然它大部分时间都是一个可爱的工具,它开始成为一个另一种意义上的工具。它合并了更改,但是某些字符串在合并时没有正确匹配,因此每次执行扫描源时,它会创建100个新的重复键以及我之后的10个字符串,因此它可以使更多工作。
Linguan (v1.1.3) whilst it is a lovely tool most of the time, it is starting to be a tool in the other sense. It merges the changes but some strings aren't matching correctly when it merges, so everytime it does a Scan Sources it creates 100 new duplicate keys as well as the 10 strings I am after so it is making more work.
FileMerge 如下所示,尝试在旧版本和新版本的 genstrings
输出文件之间进行差异处理。 genstrings
输出的字符串按字母顺序排序,因此分散在1000个字符串中的10个字符串表示要查看的差异为200。它保持匹配 /*...*/
和...=...
并说 ...
已更新。它尚未更新,只是转移到文件中的新位置。越来越多看起来我将不得不编写一个自定义工具。
FileMerge As suggested below try doing a diff between old and new versions of the genstrings
output files. The genstrings
output has the strings sorted alphabetically so 10 strings scattered throughout 1000 means that there are 200 differences to review. it keeps matching the /*...*/
and the "..." = "..."
and saying that the ...
has been updated. It hasn't been updated, just shifted to a new location in the file. More and more it is looking like I am going to have to write a custom tool.
MacHG + FileMerge 在旁注上,由于某些奇怪的原因,不喜欢使用Localizable的工作副本从存储库中做差异.strings。左窗格和右窗格都显示为空。
更新:将某些变更集中的变化保存为UTF-16,而某些变更集则以UTF-8为主,并且能够进行正确的差异。
MacHG + FileMerge on a side note, for some strange reason doesn't like doing diffs out of the repository with the working copy of Localizable.strings. Both the left and right panes appear empty.UPDATE: Turns out variations in some changesets being saved as UTF-16 and some as UTF-8 are screwing with it being able to do a proper diff.
Bash Script + FileMerge 每次添加新的 NSLocalizedString $ c $后,我编写了以下脚本来帮助维护我的英文参考文件c>条目:
#LOCALISATION UPDATE SCRIPT
#
#This will create a temporary copy of the current 'en' reference file then generate the
#latest reference file using the 'genstrings' tool. Finally forcing FileMerge to launch
#and diff the changes.
#
#Last Updated: 2014-JAN-06
#Author(s): Josh Wilson
clear
#assuming this script is run from $SRCROOT
#Backup Existing 'en' reference
cp "en.lproj/Localizable.strings" "en.lproj/Localizable-src.strings"
#Scan source files for 'NSLocalizableString' macros
genstrings -q -u -o en.lproj Classes/*.{m,mm}
genstrings -q -u -a -o en.lproj Classes/iPad/*.{m,mm}
genstrings -q -u -a -o en.lproj Classes/iPhone/*.{m,mm}
#Force FileMerge to launch and diff the update (NOTE: piping to cat forces GUI to open)
opendiff "en.lproj/Localizable-src.strings" "en.lproj/Localizable.strings" | cat
#Cleanup up temporary file
rm "en.lproj/Localizable-src.strings"
但是这只更新了EN文件,我没有办法用新密钥更新其他语言文件。这个对于我没有英文单词作为密钥和genstrings炸弹我的
welcome_message=欢迎!
带welcome_message=welcome_message
But this only updates the EN file and I am lacking a way of having the other language files updated with the new keys. This one has been good for instances where I don't have an english word as the key and genstrings bombs my"welcome_message" = "Welcome!"
with "welcome_message" = "welcome_message"
POEditor 。这是一个基于1000个字符串的在线工具和订阅。似乎运行良好,但如果有非基于订阅的工具会很好。
POEditor http://poeditor.com/. This is an online tool and subscription based after 1000 strings. Seems to work well but it would be good if there was a non subscription based tool.
Traducto Pro 似乎可以很好地整合使用XCode并提取字符串并将事物合并在一起。但是在完全翻译之前不可能从中获取任何东西,因此你被迫使用他们的翻译服务。
Traducto Pro Seems to do an alright job of integrating with XCode and extracting the strings and merging things together. But it is impossible to get anything back out of it until it is fully translated so you are coerced into using their translation services.
当然这个功能已经实现过了。 Apple如何保持他们的应用程序本地化?
Surely this functionality has been implemented before. How does Apple keep their Apps localised?
脚本迷们,我打电话给你! iOS开发已经持续了一段时间,本地化很常见,现在肯定有一个成熟的解决方案吗?
Script junkies, I call upon thee! iOS development has been going on for some time now and localisation is kind of common, surely there is a mature solution to this by now?
Python脚本
Python Script update_strings.py: Stackoverflow finally recommended a related question and the python script in this answer Best practice using NSLocalizedString looks promising...
经过测试并以当前形式(2013年5月31日),如果您有重复的评论条目(期望单行注释),它不会处理多行注释。
Tested it and in its current form (31-MAY-2013) it doesn't handle multiline comments if you have duplicate comments entries (expects single line comments).
可能只需稍微调整正则表达式。
Might just need to tweak the regex's a bit.
推荐答案
结帐 ,它完美地解决了您的问题。此外,开源,积极维护,可以在项目中轻松安装和集成。
Checkout BartyCrouch, it perfectly solves your problem. Also it is open source, actively maintained and can be easily installed and integrated within your project.
安装 BartyCrouch通过) :
In order to keep your Localizable.strings
files updated over time I highly recommend adding a build script (instructions on how to add a build script here):
if which bartycrouch > /dev/null; then
# Incrementally update all Storyboards/XIBs strings files
bartycrouch interfaces -p "$PROJECT_DIR"
# Add new keys to Localizable.strings files from NSLocalizedString in code
bartycrouch code -p "$PROJECT_DIR" -l "$PROJECT_DIR" -a -s
else
echo "warning: BartyCrouch not installed, download it from https://github.com/Flinesoft/BartyCrouch"
fi
除了逐步更新 Localizable.strings
这些文件也会确保您的Storyboards / XIBs字符串文件保持更新并添加新密钥。
In addition to incrementally updating your Localizable.strings
files this will also make sure your Storyboards/XIBs Strings files stay updated with newly added keys.
确保有关其他信息,请访问查看BartyCrouch。
Make sure to checkout BartyCrouch on GitHub for additional information.
这篇关于iOS本地化 - 仅使用新字符串更新Localizable.strings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!