Situation:
We use XCode exporting/importing tools to generate localizable files for our translators. This was going fine in XCode 8. Since we updated to XCode 9 we see a couple of problems.
Problems:
When exporting a localization via Editor-->Export for localization...-->Development language only, it doesn't include NSLocalizedString() key/values as it should according to this documentation: When you export localizations, Xcode searches your code for the macros and includes the strings files in the exported localization file for translation.
Comments that are added to the Localizable.strings development-language file seem to be non-existent in the export .xliff file.
When importing a translated .xliff file, XCode seems to delete all the comments that are in the file. It gets replaced by "(No Comment)"
Configuration:
XCode 9.0 (9A235)
Dev language: NL
Localized languages: Base, NL, DE, BE, LU
Objective-C & Swift hybrid project
What I've tried:
I have tried looking at XCode 9 documentation or changelog to see what has changed in Localization, though nothing I can find mentions this change
I can get my NSLocalizedString() strings to show up in the export when I first generate the development Localizable.strings file manually, by using the commandline command find ./ -name "*.m" -print0 | xargs -0 xcrun extractLocStrings -o . (I run it a second time for .swift files as my project is a swift/objc hybrid). Then combine the results, which let my strings show up in the export, however without comments, which are needed as guides for translators.
Question:
Is this an XCode 9 bug? Did I miss any documentation or new feature/option for localization exports/imports? Are there workarounds?
This is an older question, but I had this same issue with Xcode 10.
The solution is to simply place the strings files (e.g. InfoPlist.strings) in the same folder as plist.info. Only then are existing translations included in localization exports.
Previously I had them in a dedicated "Localizations" group. While this works for the localization itself (i.e. when running the app), localization exports seem to only include translations from existing strings files that are "near" plist.info.
What fixed both importing and exporting for me was turning off Base Internationalization by unchecking Use Base Internationalization under Project > Info > Localizations. I set all my translations in code, so I don't need it enabled for my .storyboard and .xib files.
Previously, when it was enabled, the "Localizable.strings (Base)" file didn't have anything in it, but Xcode 8 still seemed to work properly by using what was in my "Localizable (English)" file when exporting. For Xcode 9, if I had the source text in Localizable (Base) then exporting worked fine, but I still had problems with importing.
I am using Xcode 9.4.1.
I finally found the reason of the issue.
The issue exists because Xcode never saved files in the encoding it promised.
There are two places to set text encoding, one is "Default text encoding", which including a "convert existing files on save" checkbox.
There is also a file specified "Text Encoding" on each file when you open it. If you don't specify the text encoding on the file, the "Default text encoding" is used.
However, Xcode never saved the file as it promised. For example, if you choose a file specified text encoding, say to "UTF-16", an alert window shows with "Cancel", "Reinterpret", "Convert".
As the alert said, if you chose convert, Xcode would convert the file to the encoding. However, it didn't.
So when you exporting the translations, the file is opened with the encoding it never converted to and ignored.
You can verify that by these steps.
choose a source file.
change it to another text encoding.
in the alert window, choose convert
in Xcode, right click the file and choose Show in Finder.
quit Xcode.
open the file with another text editor that can deal with text encoding, mine is BBEdit.
in BBEdit, choose file -> save as
Now you can see, that the file is not saved in the encoding as it promised.
Solution
The solution is easy. For files that you specified the text encoding, keep it saved in the encoding that it specified. You can do that with other editors, like BBEdit, by save as and choose the right encoding.
For those files that are not specified text encoding. Be sure them are saved as "Default text encoding". If not, change the "Default text encoding" so you won't need to change each file.
Earlier iOS supported Localizable.strings. In iOS10, for handling pluralisation etc iOS introduced new format "stringsdict". Can we just have stringsdict file for all localisation or do we have to maintain multiple files.
I had given support for multiple languages inside my iOS project using string localization. I had added supported language Localizable.strings files from project setting. But how to do same thing for language which is not available in Xcode list(like indian language sindhi).Please suggest for same.
I started localizing my iPhone app from English to Portuguese, I added all necessary macros and changed the storyboards following the steps described on the official docs. When I finished I exported it to a Xliff xml file, as expected all english sentences were present on the resulting xml file. I continued the process by translating all sentences to portuguese and imported the xliff file into Xcode. I can now run the app and see all sentences in english or portuguese depending on my simulator configuration and everything works as expected.
Once I imported the XLIFF file there were several files created one of them being the Localizable.strings file which has the mapping between english and portuguese. I have continue developing my application and I'm now in the phase where I want to translate the new english strings I added to the project to portuguese. I tried the same process:
Export XLIFF with the current translations
Modify the XLIFF
Import it again back into Xcode
But for some reason that I'm not aware of I get a "Duplicate localized resource Localizable.strings found ".
Question being: How can I export a XLIFF file with the current translations in a way that I can modify it and import it to xcode again ?
Thanks in advance
Ze
I'm using a binary framework in my iOS project. This project is only available in english, but I would like to localize it. Assuming the original author used NSLocalizedString everywhere, is it possible to localize this framework "from the outside"?
It should be possible putting the translations in the Localizable.strings file. It should be easy to try...
If it does not work, sometimes libraries include a localizable strings file in a bundle. Then you should put your translations there.