iOS Localization - Updating Localizable.strings with just new strings
Asked Answered
C

4

34

I have searched Google and StackOverflow and still have no clear answer on an easy and automated way of doing this but here is the scenario:

  1. I have an app with 1000 strings localized into en, fr, de, es, it.
  2. I build a new feature that makes 10 distinctly new NSLocalizedString() keys.
  3. I just want those 10 new strings appended onto the ends of the files:
    • en.lproj/Localizable.strings
    • fr.lproj/Localizable.strings
    • es.lproj/Localizable.strings
    • de.lproj/Localizable.strings
    • it.lproj/Localizable.strings

genstrings will retrieve all 1010 distinct strings. This is a pain since I'll need to "needle in a haystack" find those 10 strings every time I do an update.

UPDATE 19-SEP-2014 -- XCode 6 - Apple has finally released support for XLIFF export and import of your .strings files Whats new in XCode 6? Localisation

Linguan (v1.1.3) whilst it is a lovely tool most of the time, it is starting to be a tool in the other sense. It merges the changes but some strings aren't matching correctly when it merges, so everytime it does a Scan Sources it creates 100 new duplicate keys as well as the 10 strings I am after so it is making more work.

FileMerge As suggested below try doing a diff between old and new versions of the genstrings output files. The genstrings output has the strings sorted alphabetically so 10 strings scattered throughout 1000 means that there are 200 differences to review. it keeps matching the /*...*/ and the "..." = "..." and saying that the ... has been updated. It hasn't been updated, just shifted to a new location in the file. More and more it is looking like I am going to have to write a custom tool.

MacHG + FileMerge on a side note, for some strange reason doesn't like doing diffs out of the repository with the working copy of Localizable.strings. Both the left and right panes appear empty. UPDATE: Turns out variations in some changesets being saved as UTF-16 and some as UTF-8 are screwing with it being able to do a proper diff.

Bash Script + FileMerge I have written the following script to help maintain my english reference file after each time I add new NSLocalizedString entries:

#LOCALISATION UPDATE SCRIPT
#
#This will create a temporary copy of the current 'en' reference file then generate the 
#latest reference file using the 'genstrings' tool. Finally forcing FileMerge to launch 
#and diff the changes.
#
#Last Updated: 2014-JAN-06
#Author(s): Josh Wilson

clear
#assuming this script is run from $SRCROOT

#Backup Existing 'en' reference
cp "en.lproj/Localizable.strings" "en.lproj/Localizable-src.strings"

#Scan source files for 'NSLocalizableString' macros
genstrings -q -u -o en.lproj Classes/*.{m,mm}
genstrings -q -u -a -o en.lproj Classes/iPad/*.{m,mm}
genstrings -q -u -a -o en.lproj Classes/iPhone/*.{m,mm}

#Force FileMerge to launch and diff the update (NOTE: piping to cat forces GUI to open)
opendiff "en.lproj/Localizable-src.strings" "en.lproj/Localizable.strings" | cat

#Cleanup up temporary file
rm "en.lproj/Localizable-src.strings"

But this only updates the EN file and I am lacking a way of having the other language files updated with the new keys. This one has been good for instances where I don't have an english word as the key and genstrings bombs my "welcome_message" = "Welcome!" with "welcome_message" = "welcome_message"

POEditor http://poeditor.com/. This is an online tool and subscription based after 1000 strings. Seems to work well but it would be good if there was a non subscription based tool.

Traducto Pro Seems to do an alright job of integrating with XCode and extracting the strings and merging things together. But it is impossible to get anything back out of it until it is fully translated so you are coerced into using their translation services.

Surely this functionality has been implemented before. How does Apple keep their Apps localised?

Script junkies, I call upon thee! iOS development has been going on for some time now and localisation is kind of common, surely there is a mature solution to this by now?

Python Script update_strings.py: Stackoverflow finally recommended a related question and the python script in this answer Best practice using NSLocalizedString looks promising...

Tested it and in its current form (31-MAY-2013) it doesn't handle multiline comments if you have duplicate comments entries (expects single line comments).

Might just need to tweak the regex's a bit.

Conventionality answered 29/5, 2013 at 6:10 Comment(6)
To complete your list here is another tool: Localizable Strings Merge.Akel
Thank you for sharing you search. I did not know Traducto Pro which seems to be a great tool.I don't understand the negative point about Traducto Pro. If my understanding is correct developer can use their translations services or not by manually entering translated strings.Akel
And a link to a related question on StackOverflow.Akel
The main drawback with Traducto Pro was that we already have translators we use, and like using, so switching to using Traducto's services wasn't an option. So we'd need to be able to get the extracted and merged .strings files out as deliverables to our translators. Thanks for linking the other SO question and suggesting the other tool. Will have to investigate. In the end we used POEditor and forked out some money to use it. Ideally a non-subscription based tool for the task would be best.Conventionality
Ok, thank you for your answer. It seems export features are really limited on Traducto Pro and not powerful... As for me I use Linguan with translations from myself, colleagues and iCanLocalize.Akel
Great question (and answer). Have tried out POEditor and it's great - can export the diffs for translation.Ramayana
M
8

Checkout BartyCrouch, it perfectly solves your problem. Also it is open source, actively maintained and can be easily installed and integrated within your project.


Install BartyCrouch via Homebrew:

brew install bartycrouch

Alternatively, install it via Mint:

mint install Flinesoft/BartyCrouch

Incrementally update your Localizable.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 for additional information.

Manager answered 6/5, 2016 at 16:56 Comment(1)
I have moved on from iOS development but I am working with one of my colleagues to confirm is this is an appropriate solution to the problem before accepting. Thank you for contributing such a well documented answer.Conventionality
R
1

if you have the genstrings for the previous version, just a "diff" between new and old could do the tricks

EDIT: best use vimdiff to deal with utf-16 files

Redouble answered 29/5, 2013 at 9:21 Comment(1)
the genstrings output has the strings sorted alphabetically so 10 strings scattered throughout 1000 means that there are 200 differences to review. it keeps matching the /*...*/ and the "..." = "..." and saying that the ... has been updated. It hasn't been updated, just shifted to a new location in the file. More an more it is looking like I am going to have to write a custom tool.Conventionality
O
1

You can check out this Xcode Plugin I built for OneSky, it aims to improve the localization work flow for iOS/Mac OSX developers.

The string generation feature of the plugin runs genstrings and ibtool --export-strings-file to the selected source/IB files, new files will be added the project and target automatically, new strings will be merged into existing files with comments.

It will only generate/update strings for the base language, but you can make use of other features of the plugin to automate translation export and import with OneSky platform, which is free for crowdsource projects.

Occidental answered 6/6, 2014 at 4:31 Comment(2)
Without giving away NDA information I know Apple are addressing the above issue with XCode 6 with better support for localization. I'll upvote this answer anyhow since it looks like a great tool for in the meantime. Thanks for sharing.Conventionality
Now it is officially released we can say that XCode 6 supports XLIFFConventionality
H
1

You may want to check out my solution here: SwiftyLocalization

With few steps to setup, you will have a very flexible localization in Google Spreadsheet (comment, custom color, highlight, font, multiple sheets, and more).

In short, steps are: Google Spreadsheet --> CSV files --> Localizable.strings

Moreover, it also generates Localizables.swift, a struct that acts like interfaces to a key retrieval & decoding for you (You have to manually specify a way to decode String from key though).

Why is this great?

  1. You no longer need have a key as a plain string all over the places.
  2. Wrong keys are detected at compile time.
  3. Xcode can do autocomplete, so you can do something like this:
// It's defined as computed static var, so it's up-to-date every time you call. 
// You can also have your custom retrieval method there.

button.setTitle(Localizables.login.button_title_login, forState: .Normal)

The project uses Google App Script to convert Sheets --> CSV Python script to convert CSV files --> Localizable.strings You can have a quick look at this example sheet to know what's possible.

Hireling answered 13/10, 2016 at 5:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.