Xcode 6.1 - XLIFF file contains duplicated keys

501 views Asked by At

I exported the localization xliff file with no errors. I localized the file, imported back to Xcode and ran the app. Everything was good.

I exported the localization xliff file again for a second-round localization. I found many keys duplicated and they are not translated, of course. Why did this happen? Is it a bug in Xcode? How to work around it?

Side Note that might be helpful: I have test targets.

2

There are 2 answers

0
Abdalrahman Shatou On BEST ANSWER

As I expected, the Export XLIFF file includes localisation strings in test targets too. I am using Xcode 6.2 now and still there is no way to exclude test targets from this process.

I had to open the file using a text editor (for example, TextEdit) and remove all the localisation nodes for test targets.

0
Alan MacGregor On

I noticed this issue the other day, I think it's due to translation not being able to differentiate between the localisations, often using localisation you can be lazy by typing something like:

NSLocalizedString(@"Blue", nil);

Using nil is valid but provides no information as to the context of the translation, if the string is more verbose and that string will only be used once then nil should be fine. In the above example though the context could have multiple meanings (colour, feelings, etc) so when writing localised code ensure that if it is used multiple times add a comment for the code and as long as its the same as another localised bit of text the translated strings should merge

Example

  1. Creates 2 localised items

    NSLocalizedString(@"Blue", @"Colour");
    NSLocalizedString(@"Blue", @"Feeling");
    
  2. Creates 2 localised items

    NSLocalizedString(@"Blue", nil);
    NSLocalizedString(@"Blue", nil);
    
  3. Creates 1 localised item

    NSLocalizedString(@"Blue", @"Colour");
    NSLocalizedString(@"Blue", @"Colour");