0
votes

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
I would double check those Ids in Xcode's Interface Builder. Open the storyboard in IB (right click -> open with -> interface builder). Select 1 of the labels/buttons/etc, then in the Identity Inspector tab on the right (it's the little box icon in the middle) find the "Object ID". That'll be the ID used by your Main.strings file. Those numbers sound wrong, but I don't know. - dylansturg
@DylanS I've checked on Xcode's IB. The ids now are the same but, if I add another ui component (a label, a button ecc) IB generates a correct id like "kId-c2-rCX". Visual studio keeps generating simpel numerical id also with a fresh empty storyboard file. Is this a Visual studio bug? - Androidian
I tried to build my storyboard file directly from xcode IB (which generate correct ids) but the storyboard localization still doesn't work :( - Androidian
It could be a Visual Studio bug - I'm not sure. Can you try with Xamarin Studio? - dylansturg
I tried in Visual Studio and Xamarin Studio multiple times creating fresh projects and configured them step-by-step as explained in the documentation and in the sample app. It works, and now it works also in my project. I don't understand what was the problem but the structure and files are the same as show in the documentation. I've done many cleans and rebuild and I've moved files inside and outside the Resource folder. Maybe the project was dirty. - Androidian

2 Answers

1
votes

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/

0
votes

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.