Xamarin iOS storyboard localization

2019-03-06 12:30发布

I'm developing an ios app with xamarin in Visual Studio. I'm trying to add localization to my Main.storyboard file and to default LaunchScreen.xib file but I can't make it work.

I've follow the documentation here and I've also executed the sample app (which is working fine). I've copied the structure of the project and I've checked files many times but I'm not be able to see my strings localized inside the storyboard or xib files (LaunchScreen.xib).

This is my 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>

And this is a screenshot of my project structure:

project_structure

I've seen that storyboard localization ids should be like "kId-c2-rCX". This is true for my LaunchScreen.xib file but not for Main.storyboard file which has simple numerical ids like "192", "193" ecc. Could this be the problem?

What am I missing?

2条回答
别忘想泡老子
2楼-- · 2019-03-06 13:11

You have to set a default value. For example, you want to localize a textField placeHolder, than hardcode a default value for the placeholder and the localization will work.

查看更多
Rolldiameter
3楼-- · 2019-03-06 13:15

I know this is old question, but I want to tell my solution for problem.

Here is my localization structure:

enter image description here

In my solution i have renamed Main.strings -file to same name that my storyboard.

Now change you ui item localization id to string. In my project that makes the different. Here is image to show what I mean.

enter image description here

Open your storyboard in text mode and replace those id numbers to text.

Now open your Main.strings and type your item there.

enter image description here

More info from: https://developer.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization/

查看更多
登录 后发表回答