0
votes

I tried multiple times to translate my Storyboard on Xamarin but can't make it work ... First i have a Splashcreen that well call my MainStoryboard (So inside AppDelegate)

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) {
        var lang = NSLocale.PreferredLanguages[0];

        Window = new UIWindow(UIScreen.MainScreen.Bounds);

        UIStoryboard Storyboard = UIStoryboard.FromName("Main", null);
        UIViewController initialViewController = Storyboard.InstantiateInitialViewController() as UIViewController;

        Window.RootViewController = initialViewController;
        Window.AccessibilityLanguage = lang;
        Window.MakeKeyAndVisible();

        return true;
    }

I'have a storyoboard named Main.storyboard. Got en.lproj and fr.lproj inside ressource folder. Inside each folder i have a specific file named Main.strings like in the documentation (Following my project folder)

enter image description here

Example of Maiin.strings in French :

"458.text" = "Rechercher";
"473.text" = "Parametres";
"501.text" = "Informations";
"480.normalTitle" = "Mise a jour";
"481.normalTitle" = "A propos";

plist file which is also correct:

<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
  <string>fr</string>
</array>

For me all of this is correct but it doesn't work ... I still have "???" that i'have put in the storyboard. (in 458 item there is "???" but with the localization it should be converted in "Rechercher").

Thank you for your help !

1
i also had the same problem fixed by duplicating the Main.String files. if you still feel any problem feel free to comment - Fahad Rehman
Yes this is what i mean by "like in the documentation" ... - Thomas Montagnoni
Duplicate the main.string with Main~iphone.strings and Main~ipad.strings in both English and french folder. - Fahad Rehman
But i Guess i don't use class size. I Will try and let you know - Thomas Montagnoni

1 Answers

0
votes

As far as the project tree structure, you do not have to use the Resource directory, here I am using ./Design/Base.lproj/ for my LaunchScreen/Main stroyboards, and Support/en.lproj and Support/fr.lproj/ for my non-developmental languages:

The key factor with the .strings files, other than their containing folder name, is that they are flagged as BundleResources build types.

.
├── AppDelegate.cs
├── Assets.xcassets
│   ├── AppIcon.appiconset
│   │   └── Contents.json
│   ├── Contents.json
│   └── LaunchImage.launchimage
│       └── Contents.json
├── Design
│   └── Base.lproj
│       ├── LaunchScreen.storyboard
│       └── Main.storyboard
├── Entitlements.plist
├── Info.plist
├── Main.cs
├── Media
│   └── hayley.jpg
├── Support
│   ├── en.lproj
│   │   ├── LaunchScreen.strings
│   │   └── Main.strings
│   └── fr.lproj
│       ├── LaunchScreen.storyboard
│       ├── LaunchScreen.strings
│       └── Main.strings
├── ViewController.cs
├── ViewController.designer.cs
└── iOSLocalization.csproj

The entries in the info.plist such as CFBundleDevelopmentRegion do NOT effect the language shown, nor does removing entries from the CFBundleLocalizations array (this entry is for the App Store).

Yours should have two entries, en and fr, otherwise remove the .lproj folder for the languages you are not including in your app. (You can also set all the files in that folder to a build type of None.

Make sure that your device or simulator is set to correct language that you are testing your localizations against.