how to localize today extensions widget? - ios

Our application has support for multiple region and languages. When I develop today extensions widget and read App Extension Programming Guide, I still can't find a localize solution. Even if I created the Localize.strings file like a normal Xcode project, define Localize.strings file like:
"scene_people_liked"="%d people like";
use :
#define NSLocalizedString(key, comment) \
[[NSBundle bundleWithPath:moLocalizedPath] localizedStringForKey:(key) value:#"" table:#"Localizable"]
and call it with:
NSLocalizedString(#"scene_people_liked", nil)
, it still does't work. Anyone has an idea about this problem?

Check that your TodayWidget target has the Localizable.strings files in the target membership.

take some time i has been resolved this problem.
if you want localize your today extensions widget, actually it was does't have any different step with do it in a normal project.
but it has litter problem about "Localize.strings" file name, you must have use "Localize" to named "Localize.strings" file in the normal project。localize should be work,but if you use it same name as main application or use some "InfoPlist.String" keyword,
even if test everything fine when you debug your project ,but when you package it up and install device, you will find out the localize can't get the value, so you must define a customer name without "Localize.strings" or some keywords.
:)

Related

How to change localisation from storyboard to strings file

TLDR: Xcode generated storyboards for each language, however I want the "old"(?) *.strings files. How?
I am currently in the process of localising my storyboards. After I enabled everything, Xcode generated another storyboard alongside the original (english) one for me to localise. I was surprised, I expected a Localizable.strings file, like the apple documentation still states as of April 3, 2021:
For storyboard and XIB interfaces, select the user interface files (files with a .storyboard or .xib filename extension). Xcode adds a strings file to the localization folder that contains the text to translate, as well as comments that describe the user interface components. For example, if you add German to an iOS app that uses storyboards, LaunchScreen.storyboard becomes a group containing a LaunchScreen.storyboard (Base) and LaunchScreen.strings (German) file.
I searched around the internet, in apple developer forums, watched both WWDC18 and 19 talks about localisation in Xcode, but did not find a single mention of translated storyboards.
After the initial translation, which works great due to the simplicity of just filling everything in, it gets frustrating however, since every layout change needs to be repeated for every language. This can't be intended, there must be a better way, right? Sadly, I didn't find anything. Even a hint to a piece of documentation regarding these storyboard copies would be greatly appreciated. Thanks!
There are some screenshots of the possibility to convert these two formats via a dropdown, like the third picture in this post. However for me, there is no dropdown next to the language item when I click the storyboard, neither on the group, nor individual base or localised ones:
Is this a bug or am I missing something here? I am using macOS Big Sur 11.2.3 with Xcode 12.4 (12D4e).
Turns out, you need to use the Base Localization feature, the dropdown then appears and you can convert existing storyboards to *.strings files.

Xcode 9.2 crashes exporting or importing xliff

I can see that this is a recurring problem with all sorts of Xcode versions. I'm using the latest non-beta build (9.2 9C40b).
I have already localized in Spanish. Doing that involved successful exports and imports of xliff files, with same Xcode. So what changed?
I am now trying to localize to another language. This is a showstopper. Any hints? I have looked through all the posts about previous versions crashing, and have not found anything that works.
(And before you mention it, I am done and over with genstrings. If it exists anymore.)
I've discovered that large .xliff files (more than about 6,500 lines or 1,200 <trans-unit> elements) cause Xcode 10.1 to crash consistently near the end of an import operation.
The work-around is to manually split the .xliff file into two distinct .xliff files, each containing a subset of the <file> elements in the original file. You can then import the two resulting .xliff files into Xcode separately without crashing.
Do not translate "bundle name"
I wanted to translate to Greek Language and every time I was importing xliff files, Xcode was crashing.
I realized that the problem was, that I was also translating "bundle name".
If you did the same mistake, open xliff file, find:
<trans-unit id="CFBundleName">
<source>NameOfYourApp</source>
and delete the line
<target>...</target>
After that everything worked perfect for me!
Here's a workaround. Select your project icon in the Project Navigator. Select Info at top (as opposed to Build Settings). Under Localizations, click the + button and add your new language.
Xcode will create the new .strings files and fill them up with pre-existing translations. (If there are any.) Strangely, for me, some of the new .strings files were filled in with English, some with Spanish.
In any case, you have the new .strings files and can manually paste in the translations for the new language. If your app doesn't have too much user-facing text, this isn't onerous.
But really, with this problem going back to Xcode 4 (!) one would think it would be fixed by now.
it's a late answer I know, and I'm using Xcode Version 10.1 (10B61) already.
In my scenario, I added Chinese Hong Kong (zh-HK) language under Project > Info > Localization and exported successfully then sent to the agency for translations. After few days they sent to me Chinese translated text within. At that point, everything seems correct for me by eye. But I've tried 10 times to import file and it crashes 10 times without exception! Which makes me sick. I use to checked to see the difference between 2 document via Apple's File Merge App. I understand that agency geniuses added few missing <\target> tags. Hmmm, that means while exporting Xcode didn't add for some translations <\target> tag. Interesting...
I removed those unnecessarily translated tags and checked everything was equal in 2 documents except translations of the words to the Chinese language.
Tried to import again. Then BOOM! It works like a charm! I was surprised by this. It's so weird that Xcode never shows me a descriptive message about my mistake. Probably, It's just a parse error for Xcode.
Whatever, I hope this will work for someone else.
Best.

Storyboard localization excludes a single file in iOS

I am facing a very obscure issue.
I've got an app that needs to be localized in three Languages, English, French, German. There's multiple localization files as I've got multiple storyboards ( each storyboard has one for each language).
Everything works great and things translate properly except for ONE file in ONE storyboard in ONE language. So this specific storyboard I call "Authentication" works for all languages except for the German one.
I've checked. the file is:
included in all targets
is also found in Build Phases copy phase
has the correct name.
has the correct formatting (in fact i am not allowed to build at all if the formatting is not correct in this version of Xcode.)
I am out of ideas and resorting to asking here to see if theres anything i might be missing in my series of checks.
Thanks all
SOLVED.
The answer lies within my third point
has the correct formatting (in fact i am not allowed to build at all
if the formatting is not correct in this version of Xcode.)
Beware everyone. This might seem like it is the case but it does not apply to everything. If there's a syntactic error in the Localizable.strings file, xcode will let you know and refuse to build.
HOWEVER if there's a syntax error in the YourStoryboard.strings file, the process of building will go on UNHINDERED.
Since an issue in syntax was halting everything for Localizable.strings i was wrongfully assuming that such a check would take place for all translation files. It doesnt!
Hope this saves someone in the future

iOS App Localization: Storybords Translation

My storyboards appear to be translated when previewed in XCode but when I install the app on the device nothing is translated to other languages. Here is the checklist.
Storyboards are all translated:
I have some duplicates here - perhaps the reason it is not working:
And finally local file structure on my computer:
Question: how to verify correct file linking or any steps to find the issue of Storyboards not working on the iPhone or Simulator.
You need Base.storyboard and other should be ##language##.strings. Inside these files you will translate things corresponding to ID of the element.
You can check explicitly if the string is translated by calling something like:
NSLog(#"%#", NSLocalizedString("AWO-r7-rD4.text",nil));
You should put instead of "AWO-r7-rD4.text" one of the IDs from Localizable.strings for storyboard.
For comparison:
I have Auth.storyboard, and it can be nested to: Auth.storyboard(Base), Auth.string(English), Auth.String(French).
One stupid thing: Have you changed regional settings in simulator settings?
Hope it helps.

How to localize iOS (iPhone/iPad) app using only single storyboard?

I was wondering if somebody could explain in the details how I can localize an iOS app using only 1 storyboard. I know how to localize by creating several storyboards(one storyboard for each used language), however I'd like to find out another solution.
Thanks.
The tutorial on raywenderlich.com uses two forms of localization together. The reason is he also checks the storyboard when turning on localisation in image 3:
.
So then what?
NSLocalizedString is very useful, any text set programatically can (and should) be localised using this method. Ray's tutorial is still very useful.
However, it's not very desirable to create a clone of the storyboard(s) to do translation, it's just not very maintainable in the long run.
And what about storyboards?
The magic happens using the Base Localization feature. Base localization uses the generated objectId's to 'map' different languages to the storyboard.
Do note that this feature is only available using SDK 6.0 and above. Running the app on a lower iOS version will not cause any errors, it'll simply won't work.
Go to your project, and select Base Localization, then add any other language.
Open your storyboard file and check the new language as well. Note the icon is not a storyboard icon, but a simple text file icon. That's a good thing; it won't copy the whole storyboard this time :).
Note how there is now another file 'under' the storyboard. Xcode automatically generates a file for every language you select.
You can se Localization feature for this. You need to add the Localizable.strings file for each supported language and use it for locaization.
You need to use : NSLocalizedString() for fetcing data corresponding to each key.
Check this tutorial for details.

Resources