One localization source for code and design - ios

Is there any way to use just one file for localizing texts in Xcode 7 and above?
Maybe some kind of macro/script in Xcode.. whatever..?
I mean making the storyboard/IB resources to use the words directly from a Localizable.strings file instead of having the code using the texts from localizable and the storyboad having their own localization files.
Please share your opinions/solutions about that. Also please do not mention the solution of entering everything through code, that does not seem valid/recommended.

Here's how you can consolidate your localisable content into a single file to send out for translation:
With your Xcode project open, select the project file
Editor -> Export for Localization...
Follow the steps
You will then get an .xliff file for each language that you want to have as part of your app. Send this out to your translators, and they will send it back, with the localised content. Once that's done, simply do the same steps, but for importing instead:
With your Xcode project open, select the project file
Editor -> Import Localizations...
Follow the steps

Related

Xcode 10 - How to refresh localization of a Siri shortcut intent definition file?

I have an intent definition file for a Siri shortcut. When I click on localize Xcode does very well create a localization file, each string beeing used is present with an ID.
But how do I refresh this if I added a new intent in the same file or just added a new possible response to the same file?
I currently only found two ways:
Delete localization and set up new again (which makes you loose all translated strings in all languages besides default).
Export all translations for the whole app and reimport (which leads to problems if your complete app is not yet ready for new localization export/import).
So, does anybody know a way to refresh the auto-localization of an intents definition file?
I ran into the same problem lately, and I managed to fix it with a simple workaround and two small, quick and dirty scripts:
Be sure to have your old localizations .strings files in your git repository
Uncheck all your .intendefinition localizations (and delete them)
Check back all your localizations, it will recreate the .strings files, but without your old translations (hopefully, they are safe in git)
DO NOT COMMIT THEM (yet)
For each .strings file run my little script this way: {script-path}/update-modified-strings-file.sh {project-path}/xx.lproj/YourIntents.strings
Check if everything is ok
Commit
Live long and prosper...
Please be sure to put both scripts in the same directory:
Shell script to call: https://gist.github.com/letatas/221ea3d04e70996d026362de57c1b084
Swift script called by the first: https://gist.github.com/letatas/9a58ad4f0a979b19579334bd80516f4a
The first script checks out the old version of the strings with your existing translations, the second merges the new file containing new entries with the old existing translations.
Hope this helps.
I wish Apple would fix with this.
In the meantime, the easiest way of dealing with it that I've found is this...
Add support for a new language in your project. For example, add Australian English. Then you'll get a new .strings file with all the new keys in it with the values from your intents definition.
Paste the contents of that into your existing English version and delete support for that new language.
If you want to get the new keys merged into your existing localised .strings files then you can use this https://github.com/Flinesoft/BartyCrouch Once it's installed you can run bartycrouch update and it'll sync the changes into all your .strings files.
I have the same question, i played around with this exact thing tonight. From what i can see, i have to remove all localized files and recreate them, just like you said...

Localizing custom SiriKit intent

My Xcode is v10 and I'm developing a custom intent for SiriKit, targeting iOS 12.
In Xcode 10, custom intents are designed in .intentdefinition files, where you can define your own parameters for intent phrases as well as the title of the intent and Siri shortcut for that intent. Building a project with a .intentdefinition file makes Xcode automatically generate an INIntent derived class for that intent.
My issue is that in order to support other languages than English so that the intent's title is show in the system's language in General > Siri & Search when the user is able to manipulate shortcuts for custom intents, I need to provide localized intent title for my .intentdefinition file.
When I try to add another language for my .intentdefinition file in the File Inspector and then build the project I get:
duplicate output file '/Users/.../IntentDefinitionGenerated/Intents/MyCustomIntent.swift' on task: IntentDefinitionCodegen /Users/.../ru.lproj/Intents.intentdefinition
This is likely happening because Xcode sees multiple .intentdefinition files in .lproj folders and tries to generate a same named class for each of them.
How do I localize my .intentdefinition file for iOS 12?
Go to intentdefinition file -> File Inspector -> Select Localize -> Now select current language for your intentdefinition file.
This will convert your existing intentdefinition file for current language.
Now again select the same intentdefinitionfile, add other language -> it will create a new Intents.strings file where you can customize the text for other locales.
I had the same issue as #desmond-hume. In my case, I have an old xcode project that already contained some localizations before "Base" was available. The initial .intentdefinition file must be added as the Base localization. From there, further localization can be added and Xcode will add only a .strings file for each localization.
Without a base localization, Xcode adds a new .intentdefinition for each localization which causes the "multiple commands produce...." error.
You can add a Base localization under the main project settings via a checkbox.
Some old projects (like mine) may also run into this issue:
iOS - Using Base localization pane is always empty
It looks like you've already localized your Intent Definition file (since Xcode has put it into a ru.lproj folder) so the problem might be that you've two copies of the file in the "Compile Sources" build phase.
Go here:
Project -> App target -> Build Phases -> Compile Sources
and look for duplicate entries. If you find a duplicate, delete one of the copies
You can also try Editor > Validate Settings… to find duplicates
You can also try cleaning the build
I've recently Localised the intents for my App, however after the original localisation, I added another Intent.
In Xcode 10.2.1 at least that I've checked, there is an "Export for Localization" option when you select the top level of your project.
It will ask you to save the output.
When you investigate your output, you should see an .xcloc folder for EACH of the languages you support.
Dig down to the .xliff under "Localized Contents" and open it.
There you will find your treasure trove of the items and you're looking for and you're looking for items that don't have a 'target'
The engineers at Apple at dub dub showed me this, however I personally wasn't happy of this process, as you have to edit it, and then re-import it (assuming you send off your files to a translator and get an .xliff back.
The annoyance though with Intents is the fact that it uses arbitrary IDs and not something legible
I haven't found an easier way (yet) to locate the missing translations.
Hope this helps!
you must be Project->info checked "Use Base Internationalization"
Next use the top answer method to create

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.

I deleted the Localizations in Xcode, then I cannot add any Localizations back

I deleted the Localizations of the project from the project's info by mistake. Both the storyboard and the related language were removed.
I got back the storyboard from previous file but when I want to add a new Localization, a window popped out and asked me to "Choose files and reference language to create English localization" and there is no resource file at all.
How can I add back the localizations?
Adding back a localization
When you delete your localizations sometimes you can get that situation where you can't add back any localizations in Xcode. Go to the command-line and create a ISO 639-1 two-letter language abbreviation folder with the lproj extension somewhere within your project.
Create an empty language folder
For example:
${SRCROOT}/Resources/Translations/nb.lproj
or
${SRCROOT}/Resources/Translations/en.lproj
Re-add language files to project
In the folder create an empty file called Localizable.strings and add this file to your project. Don't add the .lproj folder, just the contents. Then when you go back into the project file you will see the language under localizations. Now when you have added this, you should see the localization in your project.
No checkbox
If the added file, like a storyboard, doesn't have a checkbox next to it indicating that is part of that language localization you might need to round trip them through another language. To do this add a new language in the project. It should prompt you to copy the existing localized files over to the new language. Then delete the broken localization and re-add it.
My Example
As a specific example, I added the storyboard in the nb.lproj directory to the project. The Norwegian Bokmål appears in the project, but the checkbox for the language in the storyboard inspector won't let me add it. I created nb_NO in the project and it prompted me to copy over the storyboard. Then the storyboard had that checkbox checked. I deleted the 'nb' localization and re-added it. Now everything was the way I wanted it.
I had to solve same problem, and found one solution:
You need to find in finder your *.xcodeproj file and open it as container (ctrl+click on it and you will see it in context menu)
Here you can see project.pbxproj file, open it in Xcode. Its large (but still readable file).
(it will be better to make some copy on save spot, before you start)
Now its the task to add the missing language to this file, and its done.(U can try it on other project with localizations).
There is paragraph you need to add. Search in this file for this /* End PBXSourcesBuildPhase section */(its paragraph right before localization paragraph which is missing) and add something like this after:
/* Begin PBXVariantGroup section */
27548D921611B0BE008EA1CD /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
27548D941611B0BE008EA1CD /* en */,
);
name = Localizable.strings;
path = ../Code;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
You have to do some changes first. Look at the long number 27548D921611B0BE008EA1CD, its ID of the localization file (or some xib file, or other localizable file...), if you dont have any in the procject, just add some Localizable.string file to the project, reopen(or refresh) this project.pbxpro, and find this Localizable.string you should find something like this:
275490591611B0BE008EA1CD /* Localizable.strings in Resources */
and this is it what you need to replace in localization paragraph
also you need to do right settings on path parametr and sourceTree. This twos are readable in fileinspector in xcode.
The "sourceTree" param is Location - mostly its relative to group so sourceTree = "<group>";
The path is path relative from the group to the file (if you dont know, try to make some localization files in different project and look at project.pbxpro, what all this works)
After this you can save project.pbxpro, and you should see in xcode info section "en" localization and you can add more localizations and all other localization stuff.
In xcode 6, do the following:
With the command line, create the following directory/file structure somewhere outside your project directory:
/en.lproj/InfoPlist.strings
/en.lproj/Localizable.strings
In Xcode, open your project and choose File>Add Files to ProjectName to add the recently created en.lproj directory.
After that, you will see English in the Localizations list.
This is an old topic, but after having this issue, and then trying the solution (and having it not work exactly), I thought I'd give details on what DID work.
Like the original poster, I accidentally deleted all of my localizations and was given no obvious recourse in Xcode-- in the project settings under Info it simply said 'this project has not been localized', and when I clicked on the plus button beneath, a blank list of resource files was presented.
I followed #Cameron's guide but found that language folders with Localizable.strings files were already present in Finder, but weren't being acknowledged by Xcode. I couldn't decide how to proceed, but I happened to see an unrelated comment about adding files to Xcode, so I tried adding the existing en.lproj folder and its Localizable.strings file.
This worked, and the listing for English as the development language appeared under Info as well.
Hopefully this will help anyone who experiences the same problem!
Simply create a Folder "Base.lproj" in finder and paste the Xib you want to localize inside it, and add this folder to your project. Now you can able to add other languages without issue.
I've followed a similar approach of #user2070775 reply.
Firstyl when you delete Storyboard and Launchscreen to use your own creation or code programmatically, on Localization you might get similar following empty screen.
Then firstly you should know the language code for example to use French localization its fr etc
With project folder in the Project Navigator you must add New Group -> {LANGUAGE_CODE}.lproj. And then you should add New File -> Strings File -> Localizable.strings. In the #user2070775 answer, also InfoPlist.strings file has added so I added too for now.
In the Localizable.strings file you can add <KEY> = <VALUE> pairs for string to localizated.
Our pair is "this-is-key" = "and-this-is-value-for-spesific-language-on-localizable-string"; for now.
HINT: In key-value pair, when I did not put the semicolon, the XCode
gives error for this situation.
Until now, the following project scheme, must the result of you have.
Additionally, when you looked at the Project -> Info -> Localizations the French or etc. language must be added like in the following image.
TESTING
Basically you can get the results of the what've you done
The remaining part can be set from the Simulator. You must change the simulator language, for this answer the correct one is French.
Go to Settings -> General -> Language & Region -> French and run the project again.

Localizable.strings not found at runtime

I develop ios application (iPhone) in MonoTouch(5.2.12)/MonoDevelop(3.0.3.2)
I tried to localize it.
I created localization folders (de.lproj)(Add->New folder) and I placed 'Localizable.strings' file there. This file was added to project (Add->Add files ...).
Localization doesn't work.
I find out that localization files (Localizable.strings) don't locate in runtime place
(/user/jpa/Library/Application Support/iPhone Simulator/5.1/Applications/A99 ...B13/MyApp.app/de.lproj/), even though in MonoDevelop they are.
Why? What is wrong? File is UTF-8 coded. (It doesn't depict with UTF-16)
Thanks.
I believe you'll need to set the build action of your files to "Content" (right click file -> Build Action -> Content).
How do you call your Localized string ? Can you give us a piece of code ?
You don't need to create manually the localization folders, just:
create a Localizable.string file (Right click in project explorer then "New File")
select it
open the Xcode right panel (if not already open)
click on + in the Localization part, and select the language
This method will prevent from manipulation errors because Xcode create the localization folders itself.

Resources