iOS Storyboard Localization: Manually editing generated files - ios

I'm in the process of localizing an iOS application. I've run into a few issues though - the main one being storyboard localization. I need to add textual context to each string so that the translator can understand how the string is used. For example, in my storyboard localization for English, I will change:
/* Class = "UILabel"; text = "Label"; ObjectID = "1Sf-fE-WR8"; */
"1Sf-fE-WR8.text" = "Label";
to:
/* Context: this label is the header of the settings screen */
"1Sf-fE-WR8.text" = "Label";
Firstly - is this a bad idea? The problem is that if I ever have to re-generate the localization for the storyboard, all edits I've done on the file will disappear. How then, in the future, if I add a new element to the storyboard, will I get that element into the .strings file without regenerating it?
Note:
a) I have tried "Export For Localization", but this always results in an error "Localization failed to read a strings file"
b) The project is set up in a strange way: there is a parent project which has existing localizations, and we've added a sub-target which has it's own localized files, but the overall localization export mechanism applies to the project as a whole, and I'm worried that fiddling with it will corrupt the existing work.
Any help or thoughts are appreciated!

There's a "Comment for the localizer" text field that you can use to provide the label's usage context.
Not sure if it's still relevant to you or if it was present back in the days of Xcode 7.

Related

How can I add objects id to a localized Storyboard in XCode 9?

I've started an iOS project in XCode 9 and had all the texts and titles in English. When I localized the storyboard magically it creates a Strings file with all the object ids for the UI elements for the language spanish with and the text I should replace for that language.
Something like this:
"zxERt-qWop.title"="Texto en espanol"
I noticed when I add an element, let say a label to the storyboard, it doesn't add the objectID automatically which means I would have to write it manually.
Is there an option to add all new objects id to the storyboard string file as is done when you do the localization setup?
Yes there is. You can do it manually which is not the best thing in the world. The better option in my opinion is to do it with BartyCrouch

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
First you have to add a Strings File:
Then open the project settings and add a new language:
Mark your added strings file as target:
Find the newly added localising file. (English is automatically added)
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.

Xcode Localization: Keep translation in sync with Storyboard

Here's our localization workflow:
Build stuff in interface builder
Export project for localization
Translator looks at xliff files and applies translations for new strings (Only new untranslated strings)
Import xliff into project
This works fine for building new stuff. But if the developer changes the text in a label in storyboard that has already been translated, he will have to remember to delete the translation for that label, so the translater sees that string as untranslated. If the developer forgets to delete that translation, the translation will be wrong, which is a very hard error to find.
When code is localized like this:
var testString = NSLocalizedString("Some text in english", comment: "just a test string")
The string ("Some text in english") defines the key in the xliff-file, which means that if the string is changed, then the exported xliff file will automatically have a new string that needs to be translated.
I've tried to solve the problem with xcode's "export for localization..." function, with genstrings, and with BartyCrounch, but all methods seems to use the UI Element's Object ID as a key for the .strings-files. Which means it won't react to changes in the actual string.
The only solution I've found so far, is to set every string that need translation in the storyboards in code via a IBOutlet, but this is a quite comprehensive solution.
Do you know any tools or methods that solve this problem?
I tried what you said and understood what you meant. I think the solution is straightforward.
First, I added a new button in storyboard, named it "Test". Then I translated it in Chinese, imported the translation. Changed "Test" to "GoGo" and exported the translation again. The xliff part was changed from
<trans-unit id="jso-qF-Z1t.title">
<source>Test</source>
<target>测试</target>
<note>Class = "NSButtonCell"; title = "Test"; ObjectID = "jso-qF-Z1t";</note>
</trans-unit>
to
<trans-unit id="jso-qF-Z1t.title">
<source>GoGo</source>
<target>测试</target>
<note>Class = "NSButtonCell"; title = "GoGo"; ObjectID = "jso-qF-Z1t";</note>
</trans-unit>
What to do next
I don't know if there is a ready-tool for this. But you can use Git as it can always find the diffs.
Steps:
add you translation folder to git
commit current files
export new translations from Xcode
look at diffs with git
As you can see in the picture, git already shows what changes, that is where you should translate again.

Automating UIStoryboard localizing without duplicating .storyboard files

So far, I used to manually create a localization file for storyboards texts, writing a line like this one for each UILabel / UIButton.-
"ACCESS" = "ACCESS";
and translated them with a similar function such as the proposed here.-
Storyboard/XIB and localization best practice
I've just found a nice tutorial to automate xibs and storyboards localization.-
http://kb.applingua.com/2011/10/extracting-and-localizing-xibs-ibtool/
which uses ibtool to automate the localization files creation (a huge step indeed), BUT needs to duplicate storyboard files to 'import' the new localized labels. I don't want to duplicate my storyboards and do any change twice from now on, but function on the first thread won't work with the automatically generated files, since the generated texts are like this.-
"Qa1-zu-aC4.normalTitle" = "ACCESS";
The first approach I can think of is manually updating the generated files (still, I'd save some time, but it'd be painful as well).
Is there any way to use the automatically generated files to translate the application on runtime without duplicating storyboards?
EDIT
Just found a workaround using regex to transform
"Qa1-zu-aC4.normalTitle" = "ACCESS";
into
"ACCESS" = "ACCESS";
The regex looks like this.-
Find "([^"]*)" = "([^"]*)";
Replace "\2" = "\2";

IOS: multilanguage app

I have a questions:
I should to do a multilanguage app and I would to know a method to manage graphics elements quickly.
A method is this:
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
if ([countryCode isEqualToString:#"US"]){
//something to do
}
in this example I can set graphics elements in every viewcontroller, but there isn't a quickly solution to do all? at example in plsit file?
Yes, I think you can.
See this tutorial:
http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial
There is a paragraph where it says you can have different folders for different languages.
If that dos now work, at least you can have a singleton class where you check the "countryCode" just once, set it there and refer to it in your "if" statements.
I hope this helps.
If you are using XCode 4 just create a .strings file then in the file inspector you just hit the " +" button then you choose the language to add. In each file you will have (key, value) pairs.For example ( "firstViewTitle" = "First View"; ). the in the .m file just assign an NSLocalizedString to the title of the UI object. Befor running try to clean the target. Hope i made my self clear
You can localize every item you want in an app.
E.g. once you have imported a resource (e.g. image) inside Xcode, just select the resource in the Navigator (left side) and then in the Assistant (right side) search for the "Localization" group and click the "+" button. The first time it will create a new folder and will move the resource to that folder (default is "English"). Later you can add as many languages as you want, for each language a dedicated folder will be created by Xcode and then you will be able to change your resource locally for each language. E.g. if you have an "image button" with a text you want to localize, once you have created all these folders you will be able to change the image file locally for each. Only requirement: keep the same name of course. Then iOS will be able to fetch the right file based on the current device/simulator localization setting.
Be aware that sometime if you change stuff the bundle is not compiled correctly and to avoid headaches while debugging the easiest solution is to clean the build and remove and re-install the app from the device/simulator.

Resources