我有一个 XCode 项目,其中 XIB 接口文件是使用 Interface Builder 构建的。我正在通过使用ibtool
提取字符串、翻译它们并ibtool
再次使用来构建本地化的 XIB 文件来构建本地化的 XIB 文件。
但是,这样做意味着我必须翻译应用程序菜单中的所有项目,包括完全标准的项目(文件、保存、打开、最小化等)。有没有办法避免这种情况?
我有一个 XCode 项目,其中 XIB 接口文件是使用 Interface Builder 构建的。我正在通过使用ibtool
提取字符串、翻译它们并ibtool
再次使用来构建本地化的 XIB 文件来构建本地化的 XIB 文件。
但是,这样做意味着我必须翻译应用程序菜单中的所有项目,包括完全标准的项目(文件、保存、打开、最小化等)。有没有办法避免这种情况?
我已经为这个问题开发了一个解决方案。
https://www.corecode.io/index_opensource.html
寻找“翻译器”,它会将您的 MainMenu.strings 文件翻译成十几种语言,标准菜单项字符串的标准 Apple 翻译。
如果您发现 Aapple 的基础应用程序中缺少某些字符串或语言,请发送补丁。
所以,显然没有办法解决这个问题。
我一直在寻找类似的解决方案,我找到了这个资源
http://www.bdunagan.com/2009/03/15/ibtool-localization-made-easy/
它在文章末尾引用:
ibtool 将在 MainMenu.xib 中查找每个用户可见的字符串,并将具有关联 ObjectID 的字符串插入 MainMenu.strings,本质上是由 ObjectID 键入的字符串字典。更好的是,该工具按 ObjectID 对它们进行排序,因此版本化的 .strings 文件可以很好地区分。我可以很容易地看到添加、删除或更改了哪些字符串。让我重复一遍,因为它非常方便:.strings 文件差异很大!当然,这些 .strings 文件是 unicode 的,所以它们不是 grep'able。下面是一个字符串的输出示例:
来看看吧,我真的希望它对你有帮助,就像它对我有帮助一样!
https://github.com/core-code/MiscApps/blob/master/Translator/Translator/MainMenuTranslations.plist的翻译 器很酷,但如果您不想在构建中处理 30 个 MainMenu.string 文件(我个人不't) - 您可以将 MainMenuTranslations.plist 添加到您的资源(未压缩的 230KB 很小),然后像这样动态执行:
- (void) processMenu: (NSString*) app {
NSDictionary* d = [self loadMenuTranslations: app];
NSMenu* mm = NSApplication.sharedApplication.mainMenu;
for (int i = 0; i < mm.numberOfItems; i++) {
NSMenuItem* mi = [mm itemAtIndex: i];
mi.title = [self translateMenu: mi.title withDictionary: d];
NSMenu* sm = [[mm itemAtIndex: i] submenu];
sm.title = [self translateMenu: sm.title withDictionary: d];
for (int j = 0; j < sm.numberOfItems; j++) {
NSMenuItem* mi = [sm itemAtIndex: j];
mi.title = [self translateMenu: mi.title withDictionary: d];
}
}
}
- (NSString*) translateMenu: (NSString*) key withDictionary: (NSDictionary*) dictionary {
for (NSString* lang in dictionary) {
NSDictionary* translation = dictionary[lang];
NSString* t = translation[key];
if (t != null) {
return t;
}
}
return key;
}
- (NSDictionary*) loadMenuTranslations: (NSString*) app {
NSArray* langs = [NSUserDefaults.standardUserDefaults objectForKey: @"AppleLanguages"];
NSURL* url = [NSBundle.mainBundle URLForResource:@"MainMenuTranslations.plist" withExtension: null];
NSMutableDictionary* r = NSMutableDictionary.new;
NSDictionary* translations = [NSDictionary dictionaryWithContentsOfURL: url];
for (NSString* lang in langs) {
NSString* locale = [NSString stringWithFormat:@"%@.lproj", lang];
NSDictionary* translation = translations[locale];
NSMutableDictionary* d = [NSMutableDictionary.alloc initWithCapacity: translations.count * 3 / 2];
for (NSString* k in translation) {
NSString* v = translation[k];
NSString* key = k;
if ([k indexOf: @"APPLICATIONNAME"] >= 0) {
key = [k stringByReplacingOccurrencesOfString: @"APPLICATIONNAME" withString: app];
}
if ([v indexOf: @"APPLICATIONNAME"] >= 0) {
v = [v stringByReplacingOccurrencesOfString: @"APPLICATIONNAME" withString: app];
}
d[key] = v;
}
if (d.count > 0) {
r[lang] = d;
}
}
return r;
}
只是从
- (void) applicationDidFinishLaunching: (NSNotification*) n {
// ...
[self processMenu: @"<your app name>"];
}
我希望某处有一个 UniversalTranslation.plist(可能通过创造性地使用 translate.google.com 自动收集)