Xamarin iOS故事板本地化

时间:2016-07-20 16:13:13

标签: ios xamarin localization xamarin.ios storyboard

我在Visual Studio中使用xamarin开发ios应用程序。 我尝试将本地化添加到我的Main.storyboard文件和默认的LaunchScreen.xib文件中,但我无法使其正常工作。

我已按照文档here进行了操作,并且我还执行了示例应用程序(工作正常)。我已经复制了项目的结构,并且我多次检查过文件,但是我无法在storyboard或xib文件(LaunchScreen.xib)中看到我的字符串本地化。

这是我的Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>MyApp</string>
    <key>CFBundleIdentifier</key>
    <string>it.company.myapp</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>MinimumOSVersion</key>
    <string>9.0</string>
    <key>UIDeviceFamily</key>
    <array>
        <integer>1</integer>
        <integer>2</integer>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIMainStoryboardFile~ipad</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>CFBundleDevelopmentRegion</key>
    <string>it</string>
    <key>CFBundleLocalizations</key>
    <array>
        <string>en</string>
    </array>
</dict>
</plist>

这是我项目结构的截图:

project_structure

我已经看到故事板本地化ID应该像&#34; kId-c2-rCX&#34;。这适用于我的LaunchScreen.xib文件,但不适用于Main.storyboard文件,该文件具有简单的数字ID,如&#34; 192&#34;,&#34; 193&#34; ECC。这可能是问题吗?

我错过了什么?

2 个答案:

答案 0 :(得分:0)

您必须设置默认值。例如,您想要本地化textField placeHolder,而不是硬编码占位符的默认值,并且本地化将起作用。

答案 1 :(得分:0)

我知道这是一个老问题,但我想告诉我解决问题的方法。

这是我的本地化结构:

enter image description here

在我的解决方案中,我已将Main.strings -file重命名为与我的故事板相同的名称。

现在将您的项目本地化ID更改为字符串。在我的项目中,使得不同。这是图像,以显示我的意思。

enter image description here

以文本模式打开您的故事板,并将这些ID号替换为文本。

现在打开您的Main.strings并在那里输入您的项目。

enter image description here

更多信息来自:https://developer.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization/