在iOS上本地化剪切|复制|粘贴菜单

时间:2023-01-20 17:40:29

Im having some issues localizing a danish app ive made. (The language, not the pastry)

我在本地化我制作的一个丹麦应用程序时遇到了一些问题。(语言,而不是糕点)

I have set the CFBundleDevelopmentRegion to da_DK for danish in my info.plist, but the popup appearing for text input is still in english, even on phones running the danish OS.

在我的信息中,我将CFBundleDevelopmentRegion设置为da_DK作为丹麦语。plist,但是出现在文本输入的弹出窗口仍然是英语,甚至是运行丹麦OS的手机。

在iOS上本地化剪切|复制|粘贴菜单

How in Jobs name can i change this ?

我怎么才能改变这个?

The test device is a non-jailbroken iPhone 4S running iOS 5.1 with Danish as its iOS setting, and a danish itunes account associated.

测试设备是一款没有越狱的iPhone 4S,运行的iOS 5.1以丹麦语设置,还有一个与之相关的丹麦itunes账户。

I do not use .xibs for designs. all interfaces are programmed as viewcontrollers.

我不使用。xib进行设计。所有接口都被编程为视图控制器。

6 个解决方案

#1


33  

In the Xcode's file tree (Project Navigator) select your project. in the right hand pane select your project again. select Info and add your language.

在Xcode的文件树(Project Navigator)中选择项目。在右边窗格中,再次选择项目。选择信息并添加你的语言。

在iOS上本地化剪切|复制|粘贴菜单


I created a sample project, this is the result:

我创建了一个示例项目,结果是:

在iOS上本地化剪切|复制|粘贴菜单

#2


2  

You must localize your app in Danish to make the standard UI elements appear in that language. This is to avoid having a UI with mixed languages.

您必须本地化您的应用程序,使标准的UI元素出现在该语言中。这是为了避免使用混合语言的UI。

If you don't use xibs, you'd usually do this by adding a Localizable.strings file to your project. In Xcode's "Add File" dialog, you can use the "Strings File" template (under "Resources") for this.

如果不使用xib,通常会通过添加本地化来实现。字符串文件到您的项目。在Xcode的“添加文件”对话框中,您可以使用“字符串文件”模板(在“参考资料”下)进行此操作。

To actually localize the strings file, open the file inspector ( 1) and click the + button in the "Localization" section. You'll end up with the file being displayed as a group in the project navigator, with a sub-entry for each language.

本地化的字符串文件,打开文件检查器(⌘⌥1)并单击+按钮“本地化”一节。在项目导航器中,将以组的形式显示文件,每个语言都有一个子条目。

The strings file has the format:

字符串文件的格式为:

"Label_Text" = "Smørrebrød";

(don't forget the semicolon)

(别忘了分号)

To use localized strings in your code, you can use the NSLocalizedString macro like this:

要在代码中使用本地化字符串,可以使用NSLocalizedString宏如下:

myLabel.text = NSLocalizedString(@"Label_Text", nil);

(The second parameter is for a comment. This can be useful if you use the genstrings tool to extract localizable strings from your code and give the resulting file to a professional translator.)

(第二个参数是注释。如果您使用genstrings工具从代码中提取可本地化的字符串并将结果文件交给专业的翻译人员,那么这将非常有用。

If you use the English strings as keys, you can leave the English version of Localizable.strings empty (but don't delete it).

如果您使用英语字符串作为键,您可以保留本地化的英语版本。字符串为空(但不要删除它)。

Having a Localizable.strings file in the language that the user has selected will also cause standard UI elements, such as the editing menu, photo picker, and so forth, to appear in that language.

有一个定位。用户选择的语言中的字符串文件还将导致标准的UI元素,如编辑菜单、照片选择器等,以该语言显示。

#3


2  

If you can't get it working the official way, as provided by @vikingosegundo, you can do this with some creative engineering (Creative as in, oh my god that is dangerous). I discovered this method when I accidentally overrode [NSBundle localizedStringForKey:value:tableName:].

如果你不能按照@vikingosegundo提供的官方方式工作,你可以用一些创造性的工程来完成(比如,我的上帝是危险的)。当我意外地覆盖[NSBundle localizedStringForKey:value:tableName:]时,我发现了这个方法。

1) Add a category to NSBundle with the following methods:

1)向NSBundle添加类别,方法如下:

#import <objc/runtime.h>

+ (void) load  {
    Method original, swizzled;

    original = class_getInstanceMethod(self, @selector(localizedStringForKey:value:table:));
    swizzled = class_getInstanceMethod(self, @selector(swizzled_localizedStringForKey:value:table:));
    method_exchangeImplementations(original, swizzled);
}

- (NSString*) swizzled_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {

    NSLog(@"Key: %@. Value: %@", key, value);

    return [self swizzled_localizedStringForKey: key value:value table:tableName];
}

2) Where I simply log the key/value, you want to put an if ([key isEqualToString: xxx] ) block. In there, you want to catch (at least some of) the following key values: Cut, Copy[Menu], Select, Select All, Paste, Delete[Menu], Replace..., Define, Speak, Pause. These are the default values that can appear there.

在我简单地记录键/值的地方,你想要放置一个if ([key isEqualToString: xxx])块。在这里,您希望捕获(至少一部分)以下键值:剪切、复制[菜单]、选择、选择All、粘贴、删除[菜单]、替换……、定义、说话,暂停。这些是可以出现在那里的默认值。

3) When you have caught the value you can look up in a custom table or use hardcoded values. If you look up in a custom table make sure you have a catch in your swizzled method to avoid infinite looping in your custom table.

3)捕获值后,可以在自定义表中查找或使用硬编码值。如果您在自定义表中查找,请确保在您的swizzled方法中有一个捕获,以避免在自定义表中出现无限循环。

NB: Why do you need to swizzle? Because this over-rides all Apple text for you app. You will still want the defaults for all the other strings, so you need to swizzle to get the defaults for the strings you aren't interested in.

护士乙:你为什么要刷呢?因为这将覆盖你的应用程序的所有苹果文本。你仍然需要所有其他字符串的默认值,所以你需要为你不感兴趣的字符串获取默认值。

Good luck. Paul

祝你好运。保罗

#4


2  

Try adding/setting the "Localized resources can be mixed" flag in Info.plist to YES.

尝试在Info中添加/设置“本地化资源可以混合”标志。plist,是的。

#5


2  

You can do this directly in the info.plist. Something like this:

您可以在info.plist中直接这样做。是这样的:

<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
  <string>en</string>
  <string>de</string>
  <string>es</string>
  <string>ja</string>
</array>    

#6


-1  

Search if your .xib is localized (you'll find it in the inspector on the right panel) if so go to your Project/Target-Settings press the +-Sign and select "Duplicate English to Danish" or something which means the same (I can't check the right item at the moment)

如果你的。xib是本地化的(你会在右边面板的检查器中找到它),如果是,那么到你的项目/目标设置中按+-Sign并选择“从英语到丹麦语的复制”或其他意思相同的东西(我现在不能检查正确的项目)

Btw it's called iPhone 4S.

顺便说一句,它叫做iPhone 4S。

#1


33  

In the Xcode's file tree (Project Navigator) select your project. in the right hand pane select your project again. select Info and add your language.

在Xcode的文件树(Project Navigator)中选择项目。在右边窗格中,再次选择项目。选择信息并添加你的语言。

在iOS上本地化剪切|复制|粘贴菜单


I created a sample project, this is the result:

我创建了一个示例项目,结果是:

在iOS上本地化剪切|复制|粘贴菜单

#2


2  

You must localize your app in Danish to make the standard UI elements appear in that language. This is to avoid having a UI with mixed languages.

您必须本地化您的应用程序,使标准的UI元素出现在该语言中。这是为了避免使用混合语言的UI。

If you don't use xibs, you'd usually do this by adding a Localizable.strings file to your project. In Xcode's "Add File" dialog, you can use the "Strings File" template (under "Resources") for this.

如果不使用xib,通常会通过添加本地化来实现。字符串文件到您的项目。在Xcode的“添加文件”对话框中,您可以使用“字符串文件”模板(在“参考资料”下)进行此操作。

To actually localize the strings file, open the file inspector ( 1) and click the + button in the "Localization" section. You'll end up with the file being displayed as a group in the project navigator, with a sub-entry for each language.

本地化的字符串文件,打开文件检查器(⌘⌥1)并单击+按钮“本地化”一节。在项目导航器中,将以组的形式显示文件,每个语言都有一个子条目。

The strings file has the format:

字符串文件的格式为:

"Label_Text" = "Smørrebrød";

(don't forget the semicolon)

(别忘了分号)

To use localized strings in your code, you can use the NSLocalizedString macro like this:

要在代码中使用本地化字符串,可以使用NSLocalizedString宏如下:

myLabel.text = NSLocalizedString(@"Label_Text", nil);

(The second parameter is for a comment. This can be useful if you use the genstrings tool to extract localizable strings from your code and give the resulting file to a professional translator.)

(第二个参数是注释。如果您使用genstrings工具从代码中提取可本地化的字符串并将结果文件交给专业的翻译人员,那么这将非常有用。

If you use the English strings as keys, you can leave the English version of Localizable.strings empty (but don't delete it).

如果您使用英语字符串作为键,您可以保留本地化的英语版本。字符串为空(但不要删除它)。

Having a Localizable.strings file in the language that the user has selected will also cause standard UI elements, such as the editing menu, photo picker, and so forth, to appear in that language.

有一个定位。用户选择的语言中的字符串文件还将导致标准的UI元素,如编辑菜单、照片选择器等,以该语言显示。

#3


2  

If you can't get it working the official way, as provided by @vikingosegundo, you can do this with some creative engineering (Creative as in, oh my god that is dangerous). I discovered this method when I accidentally overrode [NSBundle localizedStringForKey:value:tableName:].

如果你不能按照@vikingosegundo提供的官方方式工作,你可以用一些创造性的工程来完成(比如,我的上帝是危险的)。当我意外地覆盖[NSBundle localizedStringForKey:value:tableName:]时,我发现了这个方法。

1) Add a category to NSBundle with the following methods:

1)向NSBundle添加类别,方法如下:

#import <objc/runtime.h>

+ (void) load  {
    Method original, swizzled;

    original = class_getInstanceMethod(self, @selector(localizedStringForKey:value:table:));
    swizzled = class_getInstanceMethod(self, @selector(swizzled_localizedStringForKey:value:table:));
    method_exchangeImplementations(original, swizzled);
}

- (NSString*) swizzled_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {

    NSLog(@"Key: %@. Value: %@", key, value);

    return [self swizzled_localizedStringForKey: key value:value table:tableName];
}

2) Where I simply log the key/value, you want to put an if ([key isEqualToString: xxx] ) block. In there, you want to catch (at least some of) the following key values: Cut, Copy[Menu], Select, Select All, Paste, Delete[Menu], Replace..., Define, Speak, Pause. These are the default values that can appear there.

在我简单地记录键/值的地方,你想要放置一个if ([key isEqualToString: xxx])块。在这里,您希望捕获(至少一部分)以下键值:剪切、复制[菜单]、选择、选择All、粘贴、删除[菜单]、替换……、定义、说话,暂停。这些是可以出现在那里的默认值。

3) When you have caught the value you can look up in a custom table or use hardcoded values. If you look up in a custom table make sure you have a catch in your swizzled method to avoid infinite looping in your custom table.

3)捕获值后,可以在自定义表中查找或使用硬编码值。如果您在自定义表中查找,请确保在您的swizzled方法中有一个捕获,以避免在自定义表中出现无限循环。

NB: Why do you need to swizzle? Because this over-rides all Apple text for you app. You will still want the defaults for all the other strings, so you need to swizzle to get the defaults for the strings you aren't interested in.

护士乙:你为什么要刷呢?因为这将覆盖你的应用程序的所有苹果文本。你仍然需要所有其他字符串的默认值,所以你需要为你不感兴趣的字符串获取默认值。

Good luck. Paul

祝你好运。保罗

#4


2  

Try adding/setting the "Localized resources can be mixed" flag in Info.plist to YES.

尝试在Info中添加/设置“本地化资源可以混合”标志。plist,是的。

#5


2  

You can do this directly in the info.plist. Something like this:

您可以在info.plist中直接这样做。是这样的:

<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
  <string>en</string>
  <string>de</string>
  <string>es</string>
  <string>ja</string>
</array>    

#6


-1  

Search if your .xib is localized (you'll find it in the inspector on the right panel) if so go to your Project/Target-Settings press the +-Sign and select "Duplicate English to Danish" or something which means the same (I can't check the right item at the moment)

如果你的。xib是本地化的(你会在右边面板的检查器中找到它),如果是,那么到你的项目/目标设置中按+-Sign并选择“从英语到丹麦语的复制”或其他意思相同的东西(我现在不能检查正确的项目)

Btw it's called iPhone 4S.

顺便说一句,它叫做iPhone 4S。