Multiple .string files of same language inside project - ios

I have an IOS project that has a es.lproj folder with a string file inside it. Now within the project I have a sub project (feedback system) that has its own es.lproj folder with a string file inside.
The problem is that the app when testing is choosing to translate the text based upon only one of the string files and is ignoring the other.
I want to keep the localisation for the feedback system separate so is it possible to have two of the same language files within the project?

All you need to do is use NSLocalizedStringFromTable instead of NSLocalizedString.
In your subproject, specify a table name for all of your strings.
I have a larger project with about 20 strings files using this approach.
You will probably need to use the genstrings command-line tool to generate the strings files from your code.

Related

Build more iOS Apps with the same project: Language strings

I need to maintain a project that produces two applications.
I've created two targets that share all the view Controller and Models. The only difference in these targets are storyboards and a couple of configuration files.
For Localizable.strings file I don't see any problem, as I said View Controllers and Models are shared and I've used NSLocalizedString function in these files. My doubts are related to the .storyboard files translation. Since the storyboards are really similar (they differ for the most for colors, position of some elements and for a couple of label text) I feel that is useless to maintain different strings file that contains almost the same data.
Any suggestion? Is there a way to use the same translation file for different storyboards?
If your strings are identical, I would move to Base Internationalization and keep the text in .strings files rather than in localized .storyboard files.

Should app extensions have their own Localizable.strings?

Currently using Xcode 6.3
In our (open source) application we have two targets:
Our main application 'Client'
An action extension 'ShareTo'
Both targets have localized strings via NSLocalizedString().
When I "Export for Localization", I see one <file> extension in the exported XLIFF file named Client/Localizable.strings that contains the strings for both the main application and the app extension.
Same results when doing an export from the command line via xcodebuild.
I am very sure that this export behavior changed over time: previously the strings from the app extension would end up in a separate Extensions/ShareTo/Localizable.strings entry in the XLIFF file. Not combined in Client/Localizable.strings.
So now I am wondering, is this new and correct behavior? Does this mean that app extensions lookup strings in their parent's bundle?
It really doesn't matter. If Xcode likes one, then you can concat both files together. In larger projects, instead of one Localizable.strings, we would use multiple .strings file, one for each class or one for each class assigned for a particular class using NSLocalizedStringFromTable(); Just make sure that the strings file is copied to both bundles (check the file inspector, right sidebar first tab).

Strange folder structure when adding language

My app is Base language English.
I have added German, and Xcode generated automatically a folder structure that doesn't correspond to what the documentation says. (cf screenshots from Xcode and Finder).
When I run genstrings, it only generates stuff for the english strings (the german remains empty).
I manually copy then the English strings into the German strings, but Export ignores the German strings in the cliff file
What am I missing?
Two things:
First, the de.lproj folder should be at the same level as the en.lproj folder, not a subdirectory of it. Second, you can choose when exporting to XLIFF if you want to export existing translations or the development language only. You may not be seeing that option since the folder layout is currently incorrect.

How do I get resx files to work with Xamarin.iOS for localization

I'm trying to get resource files to work in Xamarin.iOS from VS2012. Basically I've created a separate project (PCL), named xxxx.Localization, with two .resx files in it - Strings.resx and Strings.da-DK.resx. In both of them I have a string named String1 with localized version of 'Hello'. The project generates two dll's - xxxx.Localization.dll and da-DK\xxxx.Localization.resources.dll. The problem is that only the xxxx.Localization.dll is added to the final xxxx.app and then only the default language is available. How do I get da-DK\xxxx.Localization.resources.dll (and other languages) to be added to the app? Or is there any other way to do cross platform localization, that works?

Is it possible to update a localized storyboard's strings?

I localized a part of my application with creating a base.lproj storyboard and 3 string files for it. It was a month ago and after that I added new view controller to app, but this controller's buttons and labels not appear in string files
Is it possible to update this 3 storyboard attached string files or I must add new strings translations programmatically with using NSLocalizableString and Localizable.strings?
There are two options:
Option 1
Xcode can "reload" the file by converting the file to either an [Interface Builder Cocoa Touch Storyboard] file type or a [Localizable Strings] file type.
Select your base storyboard file from the Project Navigator
Find the Localization section in the File Inspector
If your file is currently a [Localizable Strings], change it to [Interface Builder Cocoa Touch Storyboard] or vice-versa.
Xcode should have converted your storyboard to the current version, while preserving your old localization efforts. Here you can change the file back to the original file type if you would like.
Option 2
Use ibtool to extract the strings in your storyboard.
Open the Terminal application
Locate your Base.lproj directory
Use this line to extract the strings:
ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings
After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file
Visit for more info: https://conyac.cc/business/columns/localization_guide_ios
Check out ReMafoX, it's a Mac app that perfectly solves your problem. It can be easily installed and integrated within your project, watch this video for a detailed walkthrough.
Alternatively, if you prefer an open source CLI tool without a GUI, you can also use BartyCrouch.
Install BartyCrouch via Homebrew:
brew install bartycrouch
Alternatively, install it via Mint:
mint install Flinesoft/BartyCrouch
Incrementally update your Storyboards/XIBs Strings files:
$ bartycrouch update
This will do exactly what you were looking for.
In order to keep your Storyboards/XIBs Strings files updated over time I highly recommend adding a build script (instructions on how to add a build script here):
if which bartycrouch > /dev/null; then
bartycrouch update -x
bartycrouch lint -x
else
echo "warning: BartyCrouch not installed, download it from https://github.com/Flinesoft/BartyCrouch"
fi
In addition to incrementally updating your Storyboards/XIBs Strings files this will also make sure your Localizable.strings files stay updated with newly added keys in code using NSLocalizedString and show warnings for duplicate keys or empty values.
Make sure to checkout BartyCrouch on GitHub or this detailed article for additional information.
You can manually add a key in your localization file. You can find the key object by selecting it on storyboard editor. Let's have a look at Object-ID in the identity inspector. It's look like "nwc-b2-19c"
On your localization update or add translation. For example :
"nwc-b2-19c.title" = "Translated title";
This one is not for everybody, but it requires no additional tools in the terminal and it's easy for small manual changes. (Do not consider this when you want to automate your process.)
Step 0: Storyboard language setup
Base (with english texts)
English (localizable strings file does not exist because the base file is english)
other languages (localizable strings files)
This step is done only once.
Now when I add something to the storyboard I do the following
Step 1: add the English localizable strings file
just mark the English line item.
This creates a completely new english localizable strings file with all the lines
Step 2: copy the new line items into the other language files
and translate them
Step 3: unmark English, remove the corresponding localizable strings file
the file was only needed to get the new line items
This is an easy and fast process, everything is done in the storyboard editor
Edit:
This process works very well with small storyboards. For example, I have a tabs based project and I have a storyboard for each tab.
Search for "storyboard reference" to find tutorials.
Good example: Storyboard reference in Xcode, where should we use it?
So each small storyboard only has a few strings to localize.
Finally, my solution was (rudimentary but effective) copy the previous translations and paste them in the a new file created by unchecking and checking the Localization language box.
This would be useful in some cases like mine when you have to change only one or two texts.
I think the best way is by using built-in export/import Localizations:
In Project Navigator choose you project folder
Choose Editor > Export For Localization,
All translations left on their places and XCode add missed strings automatically.
Additionally, before import, you can edit .xliff in XLIFF Editor (for example, online - http://xliff.brightec.co.uk) and then you don't need to do this in XCode.
then Editor > Import Localizations and choose saved .xliff file.
P.S. If you don't want to edit in XLIFF Editor and have skipped step 3, XCode can didn't save new strings. In this case open .xliff in XLIFF Editor, re-save without changes and import new file.
When you click in your storyboard, Main.storyboard for example... On right side you can see the localization menu (see atached image). If you uncheck and check again a lenguage, the file will be generated again. So I usually copy the content, I generate the file again and then I paste the content that I copied and already been translated.
This is the way that I use to update the dictionary.
I got a huge storyboard with a lot of strings there. Two languages base english and another arabic. The task was to add some fields and labels to storyboard and add localization for them without any scripts and NSLocalizableStrings.
For me helped next:
First: Ensure, you have git to prevent unexpectable changes.
Go to target screen in xcode and press Editor -> Export For Localization.... Save the ar.xliff file somewhere.
Download XLIFF Edtior.
Open ar.xliff file and make changes.
Import this file in xcode. Done! You have updated storyboard strings file.
There is an app a command line tool from Apple named AppleGlot that supports incremental localisation. I haven't tried it yet, but it looks exactly like the tool you searched for (some time ago).
Here is a script to extract strings from storyboards and xibs, and merge them with existing translations.
To run the script automatically when you build a project, put the script into your project root directory, and add a Run Script phase with the following line to a target build phases in your project settings.
./mergegenstrings.py PathToSourceDir
Or you can run the script on Terminal manually when you want to.
The script runs ibtool as Tha Leang answered. It also runs genstrings to extract and merge strings marked with NSLocalizedString in your source code. The script is based on a script in this post, which merges strings after running genstrings.
The easiest and very less risky approach is, just copy the Object ID from the storyboard and add a new key for the key in the localized file as below example:
1: Copy object id as below from storyboard for the component:
2: Add new key in localised file like below:
"DjF-dn-0ay.text" = "Borrar datos y restablecer";
Note: This is very less risky approach if you want to update only few component otherwise you can recreate localised file for the storyboard.
Xlifftool is available as a Mac app and works well. It shows all the translatable strings and objects from info.plist, localizable strings, and the storyboard.
Get it here for the mac: https://itunes.apple.com/lv/app/xlifftool/id1074282695?mt=12
Step 1: in Xcode, select your project folder in the project navigator. Then select Editor/Export for Localization...
Your translatable strings will be included in an xliff file under the language you selected for localization in Xcode.
Step 2: Open that file with xlifftool and translate or update your translations there were done previously.
Step 3: Then upload back into your project with Editor/Import Localizations...
Option 1
Xcode can “reload” the file by converting the file to either an [Interface Builder Cocoa Touch Storyboard] file type or a [Localizable Strings] file type.
Select your base storyboard file from the Project Navigator
Find the Localization section in the File Inspector.
If your file is currently a [Localizable Strings], change it to [Interface Builder Cocoa Touch Storyboard] or vice-versa.
Xcode should have converted your storyboard to the current version, while preserving your old localization efforts. Here you can change the file back to the original file type if you would like.
Option 2
Use ibtool to extract the strings in your storyboard.
Open the Terminal application
Locate your Base.lproj directory
Use this line to extract the strings:
ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings
After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file.
This is my easy way to update new text from storyboard or xib to localization string
1- use this script http://tredje.se/dev/trouble/?x=entry:entry150917-204052
2- select your localization string that you want to update and switch your language string from "Localization string" to "interface builder storyboard"
3- switch it back :)
Done.
Add a new language to localise. One that you do not need.
It will produce say Indonesian.strings for example which will contain all the storyboard buttons-names etc which you need, copy and paste all of them into all the other language.string files you have.

Resources