Custom localization system for your iphone games

__________

Localizating your application is crucial if you want to reach a broader audience, imaging how a Spanish or German kid will react if the game they try to play is in english or french, they just won't buy your game.

The iphone SDK has it's own localization system, which works very well, but as you may know the default localization system does not allow you to change the language in run-time, just use the OS default system, and it also does not allow other languages beyond what's defined on the iphone OS. So, if you want to change the language from a menu in your game there are many things you can do:
  • write your own system, which is utterly boring and implies parsing your language files, or...
  • overload and use what the framework has to offer.
This post tries to explain, first, how to the new localization system works, and second how to add localization to your system and how to use it to change the language in run-time.

Note: Although it is used for games it might be used for your own applications as well.

How the new system works

a. The iphone SDK way

The iphone SDK provides the NSLocalizableString("tag", "alternative") macro to obtain the localized string, from the Localizable.strings, for the given "tag" string or in case it didn't find a proper match it returns the "alternative" string.

I'll explain in the Implementation section how to build the Localizable.strings, just know that it has a strings in the format:
"tag" = "Localized text for the tag";
E.g.
NSString *localizedStr = NSLocalizableString(@"hello", @"Hello World");
//IF it finds the "hello" tag on the localizable.strings for the current OS language it will return the localized string.
//ELSE will return "Hello World"
b. The new way

With adding the LocalizationSystem.h and LcalizationSystem.m you add the following functionality to the default system.
  • you'll be fully compatible with what was already done.
  • you'll be able to change the language in run-time
  • you'll be able to support languages not added in the iphone OS implementation, like Esperanto, Catalá, Elfic,...
Using it:

It's usage is fairly simple, there has been defined 4 macros that extends the default functionality. These macros are:

1. LocalizationSetLanguage("language")
Using the following macro you'll be able to change the localization default language into the language you want.
// Sets the desired language of the ones you have.
// example calls:
// LocalizationSetLanguage(@"Italian");
// LocalizationSetLanguage(@"German");
// LocalizationSetLanguage(@"Spanish");
//
// If this function is not called it will use the default OS language.
// If the language does not exists y returns the default OS language.
- (void) setLanguage:(NSString*) l{
NSLog(@"preferredLang: %@", l);

NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];

if (path == nil)
//in case the language does not exists
[self resetLocalization];
else
bundle = [[NSBundle bundleWithPath:path] retain];
}
The "language" string should match what you have on you Localizable.strings file

2. AMLocalizedString("tag", "alternative")
Gets the Localized string:
// Gets the current localized string as in NSLocalizedString.
//
// example calls:
// AMLocalizedString(@"Text to localize",@"Alternative text, in case hte other is not find");
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)comment
{
return [bundle localizedStringForKey:key value:comment table:nil];
}
The AMLocalizedString works just the same way as the NSLocalizedString.

3. LocalizationReset;
Resets all settings, in case you'll allow your user to leave the language settings as default.
// Resets the localization system, so it uses the OS default language.
//
// example call:
// LocalizationReset;
- (void) resetLocalization
{
bundle = [NSBundle mainBundle];
}
4. LocalizationGetLanguage;
Gets the current set language.
// Just gets the current setted up language.
// returns "es","fr",...
//
// example call:
// NSString * currentL = LocalizationGetLanguage;
- (NSString*) getLanguage{

NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];

NSString *preferredLang = [languages objectAtIndex:0];

return preferredLang;
}

Implementation

Step 1. Creating the project

I'll use a Cocos2d 0.99.0 project as I wanted to demonstrate the system on games, but you'll be able to create the project better suits your application.

Step 2. Add localization to your project

To do so, you'll need to:
  1. in resources group within your project, right click add... -> New File
  2. I'll appear a window like the following. Go to Mac OS X -> Resources and select Strings File. Name your file "Localizable.string".
At this point you have added the localization file to you project, now open the information of the file (right click -> Get Info / cmd + i), and on the General tab press the Make File Localizable. You will get this as a result.

Now its time to add the localization you want.
tip: Name it as the language name in english. e.g "spanish", "french", "german",...

Step 3. Add the text.

Now open each of the files to add the text you want to localize, remember the format. Do it in the desired language file.

"tag" = "localized text";
"hello" = "HOLA MUNDO";
Add this point is exactly as if you were adding normal localization.

Step 4. Add the new localizatio file to your project.

You have to add the LocalizationSystem.h and LocalizationSystem.m to your project.

This can be done in two ways.
  1. Right click -> Add existing files... wherever you want to add the files, select them and click ok.
  2. You can darg from the sample project the group containing both files to your project.
Step 5. Just use the library.

1. Add
#import "LocalizationSystem.h"
In the classes that need localization,

2. Use AMLocalizableString instead of NSLocalizableString.

3. Use LocalizationSetLanguage to change the language.
LocalizationSetLanguage(@"Spanish");
CCLabel* label = [CCLabel labelWithString:AMLocalizedString(@"hello",@"Hello World") fontName:@"Marker Felt" fontSize:32];
The label will contain "Hola mundo".

Download

You can download a sample project with everything on it.
It consist of a clean project, just to be as familiar as possible, with the library added.

that will run as:

Each button represents a language added and OS, returns to the OS default language.

The files:
LocalizationSystem.h
LocalizationSystem.m

The sample project
Test project

If anyone has any suggestion or question leave it in the comments. I'll be glad to answer.
Thank you for reading.

332 comments:

«Oldest   ‹Older   201 – 332 of 332   Newer›   Newest»
Unknown said...

This is really pretty cool place I like it because it has everything I want more on this blog soon.
dentist reseda

Unknown said...

This is really pretty cool place I like it because it has everything I want more on this blog soon.
dentist reseda

Unknown said...

Regarding all aspects the blog was perfectly nice. gratis datingsite

Unknown said...

chatten met vreemden
This info you provided in the blog that was really unique I love it!!!

Unknown said...

congratulations guys, quality information you have given!!!


Wilderness Therapy

Unknown said...

best credit repair companies
Wasp dudes! Amazing stuff continues the good work.

Unknown said...

best electric shaver
If you really desire to get such type of information, visit this blog quickly.

Test7869 said...

Let's get a graphics service at very affordable rate!
Graphic Designer

Unknown said...

best electric razor 2014
Hey to everyone, it’s my first visit of the blog site; this blog includes awesome and actually best info for the visitors.

Unknown said...

I am happy to see that you have provided such an incredible and impressive blog for us. best home security companies

Unknown said...

dentist reseda
The information you have given in the blog really marvelous and more interesting.

Unknown said...

phone lookup service
The information you have given in the blog really marvelous and more interesting.

Unknown said...

credit repair companies
Each time I used to always check blog posts within the first hours in the break of day, because I like to get information increasingly more.

jazzka said...

Thanks! Great work! Now, I'm traying to play internationalized sound files, using SpriteKit. For example, I would do it like this:
SKAction *readText = [SKAction playSoundFileNamed:HLocalizedString(@"audiofile.mp3", nil) waitForCompletion:YES];
But it always plays the same file. I noticed this method is just for Strings, and there is a localizedImagePathForImg for images, so I did one myself for audio files:
- (NSString *)localizedSoundPathForSnd:(NSString *)soundname type:(NSString *)soundtype
{
NSLog(@"Searching soundPath:%@ -- %@",soundname, soundtype);
NSString * sndPath = [bundle pathForResource:soundname ofType:soundtype];
NSLog(@"Returning soundPath:%@",sndPath);
return sndPath;
}

I call it like this:
SKAction *readText = [SKAction playSoundFileNamed:HLocalizedSoundPath(@"audiofile", @"mp3") waitForCompletion:YES];

When I run it, I get:
*** Terminating app due to uncaught exception 'Missing Resource', reason: 'Resource /Users/myUser/Library/Application Support/iPhone Simulator/7.1/Applications/053433C9-2850-4CE6-821F-6BB1EF4234F9/MyApp.app/es.lproj/audiofile.mp3 cannot be found in the main bundle'

Any ideas? What am I missing?

Unknown said...

You guys present there are performing an excellent job.
top seo firm

Anonymous said...

I’m flattened for your blogs writings and blogs as well. Medical Negligence

Unknown said...

auto insurance quote
Pretty remarkable post. I simply came across your blog and desired to say that I have really enjoyed searching your blog posts.

Unknown said...

compare auto insurance rates
The written piece is truly fruitful for me personally; continue posting these types of articles.

Unknown said...

write my essay
Wonderful, just what a blog it is! This blog has provided the helpful data to us continue the good work.

Anonymous said...

I absolutely respect and appreciate your point on each and every object. watch brands

Anonymous said...

This is my very first time that I am visiting here and I’m truly pleasurable to see everything at one place. Loch Duart

Anonymous said...

I believe this is actually the most useful blog I've been through this entire day. fashion

Anonymous said...

Hey buddies, such a marvelous blog you have made I’m surprised to read such informative stuff. Loch Duart Salmon

Anonymous said...

The caliber of information that you're offering is merely wonderful. best seo agency

Anonymous said...

Your blogs and its stuff magnetize me to return again n again. life insurence

Anonymous said...

Excellent quality articles are here. This is good site with useful info. trial

Unknown said...

Wasp dudes! Awesome stuff keep it up. watch

Unknown said...

I need more articles and blogs please post soon. european watch company

Unknown said...

I’m glad to find so many useful and informative data on your website. dating tips for women

Anonymous said...

Great job you people are doing with this website. tips for dating

Anonymous said...

Bundles of thanks for providing such kind of blogs with the informative and impressive articles. panties for sale

Unknown said...

I have looked for so several posts about the blog lovers except this post is of course a nice one, keep on. http://panda-designs.com/rolex-replica/

Unknown said...

I am truly appreciative to the owner of this website who has shared this nice article at this wonderful place. Panda Designs

Anonymous said...

I would never crave to lose out any chance to look throughout your contents. cosmetic dentist south bay

Anonymous said...

Waooow!! Nice blog, this will be greatly helpful. compare car insurance quotes

Anonymous said...

Awesome! Immense information there. compare car insurance quotes

Unknown said...

Good quality info. Lucky to me I came to your website not on purpose, but now I have bookmarked it. payday advance online

Anonymous said...

This is very essential blog; it helped me a lot whatever you have provided. seo providers

Anonymous said...

I knew this blog post was existed someplace. Thanks to post such articles. Will unquestionably be using it very soon. twitter followers

Anonymous said...

Way cool some valid points! I am grateful for you making this post on hand; the rest of this website is also first-class. Have a great fun. best web 2.0 sites

Anonymous said...

Hey very nice blog!! Man you have done the Amazing efforts to make this blog... I will surely bookmark your blog. life & style

Anonymous said...

congratulations guys, quality information you have given!!! Best infographic

Anonymous said...

congratulations guys, quality information you have given!!! social media infographic

Unknown said...

Thanks friends, for providing such enlightening data.dating games

Anonymous said...

I really enjoy reading and also appreciate your work. payday loans no credit check

Anonymous said...

You have actually made the good points here. I did lots of search on the same topic and didn’t find such informative blog like yours. building business credit

Anonymous said...

Loved your blog page!!! The stuff that you have remarked up here is superbly wonderful and I vigorously thank you for the same... home security systems reviews

Anonymous said...

Amazing, what a post this is! This webpage gives helpful information to us, keep on working hard. Password Manager

Unknown said...

Loved your blog page!!! The stuff that you have remarked up here is superbly wonderful and I vigorously thank you for the same... umrah package

Anonymous said...

There is noticeably much to know on the subject of this. I think you created some excellent points in Features also. umra package

Unknown said...

I have understood everything in this article, and I need more on this to complete my study on the topic, thanks to provide such nice details. auto insurance quotes

Unknown said...

I get contented to see this selective information. Aspire Atlantis Coils

Unknown said...

Loved your blog page!!! The stuff that you have remarked up here is superbly wonderful and I vigorously thank you for the same... web 2.0 service

Unknown said...

Nice post! I am really in love with your blog thank you so0o much. High PR blog post service

Unknown said...

I truly appreciate your working guys, thumbs up!! home security systems

Jack Alice said...

Really amazing blog!!! I enjoyed the complete article? enormous written. when do i have to pay my auto insurance deductible

Jack Alice said...

You have really selected the suitable topic; this is one of my favorite blogs. auto insurance deductibles and premiums

Unknown said...

I'm also visiting this site regularly, this web site is really nice and the users are genuinely sharing good thoughts.payday loans in new york york ny

Unknown said...

Really amazing blog!!! I enjoyed the complete article? enormous written. SEO Conference

Anonymous said...

This is wonderful and quite informative blog I have learnt so many things from here. build corporate credit fast

Anonymous said...

Loved your blog page!!! The stuff that you have remarked up here is superbly wonderful and I vigorously thank you for the same... how to build business credit fast

Anonymous said...

Really amazing blog!!! I enjoyed the complete article? enormous written. build business credit

Kate Perry said...

I'm also visiting this site regularly, this web site is really nice and the users are genuinely sharing good thoughts.payday loans

Anonymous said...

This is wonderful and quite informative blog I have learnt so many things from here. judi bola online

Anonymous said...

Nice explanation here to make understand the people. Thanks for this
build corporate credit fast

Anonymous said...

I know this is quality based blogs along with other stuff.cash payday loan

Anonymous said...

This is wonderful and quite informative blog I have learnt so many things from here. online payday advance loans

Anonymous said...

This is wonderful and quite informative blog I have learnt so many things from here. online payday advance loans

Unknown said...

Backup iOS devices to your computer

Anonymous said...

This is one amongst my desired blogs; I have got enough knowledge through this. http://www.noriomatsumoto.com/build-corporate-credit-with-ease/

Anonymous said...

Thanks for the entire information you have given here to impart knowledge amongst us? painter calgary

Unknown said...

Yeah nice Work, full of great Info… This is one amongst the most Amazing Site Dude… orogoldcleopatra.com

Unknown said...

Hello! If you ever need an intuitive and online software localization platform for your translation projects, I recommend to give https://poeditor.com/ a try, because it has a friendly interface and there are some helpful features like automatic translation, API, productivity mode, realtime translation system, GitHub and Bitbucket integration, designed to simplify the collaborative translation work. It understands many language files such as .po, .pot, .xliff, .string, .resx/resw. Cheers!

Anonymous said...

Keep the ball rolling you have done the great job here. Health Insurance Jacksonville

Anonymous said...

This is wonderful and quite informative blog I have learnt so many things from here. Health Insurance Jacksonville

Anonymous said...

Hello! After browsing some amongst the post I felt this is totally new to me. Anyhow, I’m absolutely happy to find this. healthcare insurance company

Unknown said...

I know that this site has quality based content; I always enjoy reading your posts. Health Insurance Tampa

Unknown said...

This is wonderful and quite informative blog I have learnt so many things from here. nutrisystem reviews

Unknown said...

Wowww! Thanks a lot baby! I always required writing in my site something very special like your blog has. You have really helped me a lot.
car ins

ND said...

Totally Awesome to customization of iPhone game.. thanks for adding it..
Best Antivirus for MAC

Unknown said...

Excellent post guys! Your blog is attention-grabbing! Keep continuing the good work!
Lakeville bathroom remodel

Unknown said...

There is another interesting service that provides sdk and online update for ios apps translation:
http://localize.io

You can manage you localisation files without the need to think about which version of the app you're updating. You also don't need to recompile the app each time you add a new language.

Justin Bieber said...

I love this blog because it is user friendly with appreciative information.faxless payday loan

Anonymous said...

After all, what an awesome site and enlightening posts, I would surely bookmark this! learn more here

Anonymous said...

Hello! After browsing some amongst the post I felt this is totally new to me. Anyhow, I’m absolutely happy to find this. visit here

Vincent said...

How do you extract pics from iPhone backup?

Unknown said...

I was searching about this issue as you have discussed very clearly and lovely manner that I don’t have to go now any other webpage. pool builders wylie

Unknown said...

Hi there! You can localize your app for international markets by using a collaborative translation management platform like https://poeditor.com/. Its great and easy to use work interface, even by non-technical people, makes the localization process easier for all users.

Unknown said...

Unit Link Commonwealth Life - Commonwealth Life

Unknown said...

If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job. payday loans no credit check

Unknown said...

Thanks for sharing it .really informative content.
Mobile Application Development

Unknown said...

Thanks to share this blog with us .Really great job to discuss ideas about web Development

Unknown said...

nice blog.Thankew to share this post with us. Mobile app development also provide great info. about this application.

Unknown said...

Thanks to post your blog. useful content.<a href='http://www.elitesmartcare.com/"> Web Application development </a>

Unknown said...

Nice post.Thanks to share your ideas with us. Web Application Development

Unknown said...

Thanks to share this useful information with us. Nice blog. Web Development

Unknown said...

I'm also visiting this site regularly, this web site is really nice and the users are genuinely sharing good thoughts. Vine Vine Skin Care

Unknown said...

I'm also visiting this site regularly, this web site is really nice and the users are genuinely sharing good thoughts. Vine Vine Skin Care

Dr Purva Pius said...

HOW I GOT MY LOAN FROM DR PURVA PIUS LOAN FINANCE (urgentloan22@gmail.com)

Hello Everybody,
My name is Mrs Sharon Sim. I live in Singapore and i am a happy woman today? and i told my self that any lender that rescue my family from our poor situation, i will refer any person that is looking for loan to him, he gave me happiness to me and my family, i was in need of a loan of S$250,000.00 to start my life all over as i am a single mother with 3 kids I met this honest and GOD fearing man loan lender that help me with a loan of S$250,000.00 SG. Dollar, he is a GOD fearing man, if you are in need of loan and you will pay back the loan please contact him tell him that is Mrs Sharon, that refer you to him. contact Dr Purva Pius,via email:(urgentloan22@gmail.com) Thank you.

LOAN APPLICATION FORM:
=================
Full Name:................
Loan Amount Needed:.
Purpose of loan:.......
Loan Duration:..
Gender:.............
Marital status:....
Location:..........
Home Address:..
City:............
Country:......
Phone:..........
Mobile / Cell:....
Occupation:......
Monthly Income:....

Contact Us At :urgentloan22@gmail.com

Anonymous said...

webnet provides custom application development services. offering the highest quality Application development, software development services Islamabad..

Unknown said...

As flexible use is getting more broad, in this way it is key and gainful to give negligible helpful versatile portable Mobile App Development Services as they are essential for the customers and business also.

Unknown said...

Your website is terribly informative and your articles are wonderful. comprar bellavei

Unknown said...

That’s a nice site you people are carrying out there. bellavei

Anonymous said...

I read your blogs regularly. Your humoristic way is amusing, continue the good work! progressive leasing

Unknown said...

I feel happiness to read the content that you are posting. OROGOLD Cosmetics reviews

Unknown said...

Your articles make whole sense of every topic. OROGOLD

Unknown said...

Whatever you have provided for us in these posts really appreciative. car insurance

Unknown said...

Hmm!! This blog is really cool, I’m so lucky that I have reached here and got this awesome information. payday loans online

Unknown said...

It’s my fortune to go to at this blog and realize out my required stuff that is also in the quality. lifeinsurance

Unknown said...

I got this blog site through my friends and when I searched this really there were informative articles at the place. payday advance

Unknown said...

Quickly this site will indisputably be famous among all blogging people, because of its fastidious articles or reviews. auto insurance quotes

Business Intelligence said...

Hi, I do think this is an excellent web site. I stumbledupon it ;) I'm going to come back once again since I book marked it.
http://www.redsqware.com/

Unknown said...

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
wholesale Granite Stone supplier

Unknown said...

I am actually delighted to read this post that carries countless of helpful information, thanks!
German website localization

Unknown said...

Glad to read it has helped you!
Medical localization


WebMaster said...

Awesome work! test project and project files are not available. Can someone please re upload!

Unknown said...

Globalization has decidedly made promoting straightforward for various associations wherever all through the world. Translation or limitation is an astoundingly fundamental part of an association's globalization for it can speak to the snapshot of truth the associations. Here are possibilities for the Game localization companies, Game confinement Services, Video amusements limitation, Gaming Translation Agency, Gaming Translation Company and Gaming Translation Services.

Unknown said...

Just wish to say your article is as astounding. The clearness for your publish is just great and that i can think you’re an expert in this subject. Well with your permission let me to take hold of your RSS feed to stay up to date with imminent post. Thank you a million and please carry on the rewarding work. https://adamfantacy.tumblr.com/

Unknown said...

Rally support for a trigger, cherished one, group or mission by selling custom t-shirts and amassing donations on-line. https://adamfantacy.tumblr.com/

laila stephin said...

Globalization has emphatically made propelling clear for various affiliations wherever all through the world. Elucidation or confinement is an astoundingly essential part of an association's globalization for it can address the see of truth the affiliations. Here are potential results for the Game confinement affiliations, Game restraint Services, Video beguilements limitation, Game localization Services, Gaming Translation Company and Gaming Translation Services.

Unknown said...

Existem três tipos de extensões de cílios: os sintéticos, os de seda e também os de vison (mink, mamífero cuja pele é muito usada para casacos de pele). trueinvestde.wikidot.com

Unknown said...

January’s numbers have actually been owned greatly by the multi-state measles outbreak that came from two Disney amusement park in California in December, Schuchat claimed. trueinvestde.wikidot.com

Unknown said...

Por ende, la interpelación del dinero cobrado inadecuadamente como consecuencia de el requisito suelo puede reclamarse aunque cuando el parroquiano haya refrendado un contrato renunciando a sus legítimos derechos. My Blog http://xerobuff.weebly.com/

Unknown said...

Heya superb website! Does running a blog such as this take a great deal of work? I’ve very little knowledge of programming however I was hoping to start my own blog in the near future. Anyways, should you have any suggestions or tips for new blog owners please share. I understand this is off subject nevertheless I just had to ask. Thank you! My Blog http://xerobuff.weebly.com/

Unknown said...

After being informed, I do not relent giving back credit to the author for great efforts. It is usually very good to let the author know that he or she is doing a perfect job because it is through such information that the author is motivated. Even without reading much of the details in this article, it is easy to notice that it is valuable. Research paper structuring help

ss said...

Amazing information you are sharing. Thanks for it. I spent too much time to find different blogs but this is really a unique blog for me. Mobile Application Development Company

Muminah Tannous said...

I did not know about this feature before. Now i will use this in my iphone and will surely enjoy my game.
Cheap Umrah Packages

Stephanica said...

Thank you for the nice article here. Really nice and keep update to explore more gaming tips and ideas.

Game QA Company

Game Functionality Testing

Game Compatibility Testing

Apps Maven said...

Thanks for sharing this content with us.

Raj Sinha said...

Looking forward to reading more. Great blog for schools. Really looking forward to read more. Really Great.

Kendriya Vidyalaya No 1 NHPC Chamera
Kendriya Vidyalaya No 2 NHPC Chamera
Kendriya Vidyalaya Hamirpur
Kendriya Vidyalaya Nadaun
Kendriya Vidyalaya YOL Cantt
Kendriya Vidyalaya Palampur
Kendriya Vidyalaya Alhilal
Kendriya Vidyalaya Naleti
Kendriya Vidyalaya Dharamshala
Kendriya Vidyalaya Bhanala

Anonymous said...

mmorpg oyunlar
İnstagram Takipci Satin Al
Tiktok Jeton Hilesi
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
instagram takipçi satın al
metin2 pvp serverlar
instagram takipci

Anonymous said...

smm panel
smm panel
iş ilanları
instagram takipçi satın al
hirdavatciburada.com
beyazesyateknikservisi.com.tr
SERVİS
TİKTOK PARA HİLESİ

«Oldest ‹Older   201 – 332 of 332   Newer› Newest»

Post a Comment

top