NSLocalizedString only retrieving key in Submodule - ios

I am trying to use localisation inside my App. I followed Apple's documentation and various blog posts.
I created the Localizable.strings file where I put my English and German translated strings, and replacing all of the hard coded string occurrences with NSLocalizedString(#"key", nil) but after running the application in the Simulator only the key value is shown.
I also checked if it's copied to the bundle but everything seems to be fine.
My intention is to add localization to only one submodule inside my workspace which consists of multiple submodules.
Any help would be appreciated.

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...

ios - main.storyboard strings not found in base localization

In xcode 8.3.3, playing with my first serious localization. I have added two languages, "use base localization" is on, exported the xliff, imported the translations, and all seems basically as I would expect it to. I have a base.lproj folder with main.storyboard, my base Localizable.strings, and InfoPlist.strings. I have the two language lproj folders, each with their files in them. In the app, they appear organized by type:
If I set the app to run in either of those languages, it works fine (I also had to add a copy to the build phases to copy Localizable.strings and InfoPlist.strings). No errors or warnings in the console, app works and shows the correct text for storyboard strings and code.
However, when I am in the base language (English, if it matters), when the app starts, it throws out warnings for all of the storyboard strings. Something along the lines of:
2017-07-16 10:57:22.977774-0500 AppName [1574:688423] [strings] ERROR: bFh-6v-hYF.text not found in table Main of bundle CFBundle 0x101d00020 </var/containers/Bundle/Application/guidguid-guid-guid-guid-guidguidguid/AppName.app> (executable, loaded)
N.B. all of the storyboard strings are, in fact, displayed correctly in the base language, it just also throws these errors in to the log. Before I realized I needed to have base Localizable.strings, when it couldn't find those it would display the "Key", which for this project is the translatable string, but they would be displayed in upper case. That is not the case here. The app looks fine, but throws errors.
So my first attempt (after the ritual clean and rebuild), was to create a Main.strings file and try to import it as the base version of said strings, since it apparently wasn't finding them in the Main.storyboard that was already in base.lproj. No luck there, it would not let me do that - which makes sense, since it already thinks Main.storyboard is the base. Next thought was to try to copy the Main.storyboard to the bundle as part of the build phase, but that didn't help. After a day of reading articles about all the issues others have had with i18n on this platform, I haven't found quite this same problem, and am out of ideas.
I can't say that it seems like a big deal to kill these last errors, but they bother me, since otherwise it runs clean, and it runs clean in any language other than the base.
Your problem is by now surely solved, but maybe somebody else (like me) gets a similar error message:
I my case, the main storyboard was for some reason no longer localized.
I thus localized it, which created two subfiles:
So, for a storyboard to be localized, required are:
always a file Main.storyboard, in the folder Base.lproj
for every localization a file Main.strings, in the folder XX.lproj, where XX is specific for the language, e.g. de for German.
As soon as I did the localization of the storyboard, the error message disappeared.

Exporting xliff file on Xcode acting strangely

So I have a project that has been already localized in the past. But we created some new keys and we want to get them translated seperately.
Also in some languages some keys are missing, so I wanted to find those too. So what I did was to export the xliff files for translation using Xcode's export tool. I've using NSLocalizedString everywhere in my project, so theoretically that should have me covered.
But when I open an exported xliff file (let's say for Italian) I have the following problems:
The section in the xliff file for the localizable file is listed twice. The first time it's like this:
Translations for projectName/Localizable.strings
In this part of the xliff file ALL the translations are missing, even though the localizable file contains translated values for most of the keys.
Then the same localizable file is listed twice as:
Translations for projectName/en.lproj/Localizable.strings
In this case the keys all have their translated values, but if a key is missing from the English localizable file then it's also missing from here.
This is making it a huge pain for me because I'm just looking for the keys that are missing translations, and yet this way it means I have to go through the English list again to make sure no keys are missing.
This doesn't seem normal or practical to me. Anyone have any idea what I might be doing wrong?
The translated keys all work fine on the app itself by the way, tried it both on devices and the simulator.
Thank you for your help.
I do not use xliff exported files to manage my translations so I cannot give you an answer using this.
However, you may be able to solve your problem of finding missing localizations using Localization.strings files.
What you can do is use the genstrings command to generate a Localizable.strings file which will contain all the NSLocalizedString from your code.
To do this, you must pass all for your source files to genstrings.
For example, if you have a swift only project, you can just run this command at the root of your project:
find . -name "*.swift" | xargs genstrings
This will generate a Localizable.strings file you can then compare to your existing Localizable.strings file with a file compare tool like FileMerge. To make this effective, you may need to sort the keys in all the Localizable.strings files, I know a lot of editors can do this (SublimeText is one).
As you can see, the above solution is manual and will prove error prone if you need to do this more than once. In the past, I've automated this using a python script which did the following given the generated Localizable.strings and a localized strings file:
parse the Localizable.strings to get all the reference keys
parse a given localized strings file to get the localized keys
output the unused keys and the ones not translated
Hope this helps!

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.

iOS: Localization gone wrong

I'm starting to get confused..I've wanted to finally add my translation file for all strings to my app according to ray wenderlich's tutorial. But somehow now everything got messed up. I removed now every localization again, which deleted my strings file, the storyboard etc. And now I have no localization language set in the project settings and I've copied all files back from the trash.
But my localized string (NSLocalizedString(..)) somehow don't load..or load something else. I've changed some of them to check if my strings file in the project explorer is actually used but it still uses the old strings and I have no idea from where..I've checked the project folder and there aren't any other files.
How can I set up everything again that it works? How can I set the strings file it should use? And how should I set up then the localization, with or without base language?
Edit: And in the simulator I cannot get my app running..it's showing only a black screen. Whereas on my iphone it still works (if I use my iphone from Xcode).
I guess I've deleted all my languages in project settings and now I cannot add any localization anymore :-(
Here's what I would try:
Check your project folder for any leftover .lproj folders / .strings file and delete
Clean / Build
Start localization from scratch following SmoothLocalize's Tutorial
This should delete all old files and create a new default localizable.strings, and then you can add more languages.

Resources