Welcome Guest Search | Active Topics | Members | Log In | Register

Internationalising my app Options · View
cirrious
#1 Posted : Thursday, January 14, 2010 3:42:37 PM
Rank: Advanced Member

Groups: Registered

Joined: 1/13/2010
Posts: 43

 Hi

As a newbie to iphone and monotouch development, is there any "standard" way to softcoding strings - so that I can release versions in different languages.

Thanks for any pointers

Stuart

stockli
#2 Posted : Thursday, January 14, 2010 4:40:30 PM
Rank: Advanced Member

Groups: Registered

Joined: 1/11/2010
Posts: 68
Location: Switzerland

Yes there is a standard way for doing this (actually it's the standard iPhone way):

So add an .lproj folder for every language you want localization:

let's assume you added the folders:

en.lproj (english) it.lproj (italian) de.lproj (german), usw...

To each folder add a file called Localizable.strings (set as content!)

These Localizable.strings files have following content (showing the DE-version):

// comment

"House" = "Haus";

"Tree" = "Baum";

Make sure that the left-hand side is equal in all Localizable.strings-files, it's actually the keyword that you access like that:

string nameForTree = NSBundle.MainBundle.LocalizedString ("Tree", "", "");

Instead of "Tree" you could of course also use something like "treelabel.text". But Apple recommends to use non-technical word or sentence.

Since I had a lot to localize I made the code easier to read with an extra class:

using System;
using MonoTouch.Foundation;

namespace FSE.Localization
{
    public static class Loc
    {
        public static string t(string toTranslate) {
            return NSBundle.MainBundle.LocalizedString(toTranslate,"","");
        }
    }
}

So the line gets much shorter:

string nameForTree = Loc.t("Tree");

 

cirrious
#3 Posted : Thursday, January 14, 2010 8:49:47 PM
Rank: Advanced Member

Groups: Registered

Joined: 1/13/2010
Posts: 43
Thanks for the absolutely first class response.

This time... I will build in internationalisation from the start.

Thanks!
abelmartin
#4 Posted : Sunday, February 21, 2010 11:23:41 PM
Rank: Newbie

Groups: Registered

Joined: 2/21/2010
Posts: 1
Location: NYC

Stockli is spot on, except the folder name needs to end with a "j".

As in...

  • en.lproj
  • fr.lproj
  • de.lproj

Otherwise, it's perfect.  Great post!

stockli
#5 Posted : Monday, February 22, 2010 4:18:08 PM
Rank: Advanced Member

Groups: Registered

Joined: 1/11/2010
Posts: 68
Location: Switzerland

@abelmartin:

Yes you're right, I've changed that.

Thank you!

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Modified YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.301 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 1.829 seconds.