Pedro Cabaco
Pedro Cabaco

Reputation: 185

NSLocalizedString in Spritekit SKLabelNode

I've been searching all over the internet and there doesn't seem to be a clear explanation on how to localize strings using SpriteKit. Only seeing tutorials for people using the interface builder, but all I really want is, imagine this:

I have an SKLabelNode called label. And I define the text like:

labl.text = NSLocalizedString("titleOfTheScreen",nil)

So basically what I think I have to do is add the new language in the Project settings. Then, I add a new Strings file called Localized, and add it to the new folder.

But what happens to my English language? There's no file for the original one

Upvotes: 2

Views: 244

Answers (2)

Stoyan
Stoyan

Reputation: 330

From your screenshots I can see that you have "File.strings" file. You should have created "Localizable.strings" file.

Also, I can see that you have the (Base), (English) and (German) strings version. Why do you think English is not there?

In each of the files you should put strings like that:

"titleOfTheScreen" = "blah-blah";

Replace "blah-blah" with the proper translation in each of the strings files. It's important to note that the semi-colon at the end of the lines in strings files are mandatory, otherwise Xcode would issue some really funny error messages. This is easy to overlook if you're programming in Swift and trailing semi-colons are not mandatory.

Upvotes: 1

Stefan
Stefan

Reputation: 5461

First you have to add a Strings File:

enter image description here

enter image description here

Then open the project settings and add a new language:

enter image description here

Mark your added strings file as target:

enter image description here

Find the newly added localising file. (English is automatically added)

enter image description here

Upvotes: 3

Related Questions