I have localization in my app for French language which I have implemented like so...
I have a file called Localizable.strings(French) which contains all the French keywords given like so...
"Hello" = "Bonjour";
"Tree" = "Arbre";
"Sun" = "soleil";
And if I want to localize a particular label, I do it like so...
myLabel.text = "Hello".localized
Now say I get some keywords like these from an API :
"Moon" = "Lune”;
"car" = "auto”;
How can I update my Localizable.strings(French) file with these keywords programatically without having to go and manually enter the keywords I get from the API..?
I referred this link and also looked up other similar answers in SO..but couldn't get a solution yet...
Related
Our iOS app is translated into 19 languages, and recently I found an issue where two buttons on a screen had the same title - which mean that users couldn't tell which to press!
I want to write a unit test that will check two NSLocalizedString keys in a particular locale, and make sure they don't collide.
How can I lookup the value of an NSLocalizedString in an arbitrary locale?
(For example, let's say I want to find the translated versions of "Delete" and "Remove", or something like that, and make sure those two translated strings aren't the same.)
(I'm guessing that the answer is going to involve something with Bundle?)
Here's the pseudocode of what I'm looking for:
class TranslationTest: XCTest {
func testNoTranslationCollision() {
let allLocales = // list of all supported locales in the app
allLocales.forEach { locale in
let translatedStringA = "Remove".asTranslatedIn(locale)
let translatedStringB = "Delete".asTranslatedIn(locale)
XCTAssertNotEqual(
translatedStringA,
translatedStringB,
"The translations for these different strings shouldn't be identical!"
)
}
}
}
Now in Xcode 11 you can define different configurations for each test with Test Plans. So define different configurations that each one launch the app with specific language. If specific language like persian not shown in Application Language, add its language code in Arguments Passed On Launch like this:
-AppleLanguages (en)
In Your case first you need to create an array of your supported language codes and traverse through array and set language and compare your strings
let stringA = NSLocalizedString("Remove",comment: "stringA")
let stringB = NSLocalizedString("Delete",comment: "stringB")
XCTAssertNotEqual(
stringA,
stringB,
"The translations for these different strings shouldn't be identical!"
)
With the iPhone 6s, Apple has introduced a new feature called "3D Touch". App developers are able to use this technology by using it within their apps or provide so-called UIApplicationShortcutItems on the home screen which appear when you 3D Touch the corresponding app icon. I've seen quite a few people out there who wanted to know how you would be able to localize those. Here's how.
What you have to do is, if you haven't already, create a new strings file called InfoPlist.strings, then you localize this strings file to the languages you wish via the File Inspector on the right.
Now, you write down a key (for example: ADD_ITEM_SHORTCUT_TITLE or ADD_ITEM_SHORTCUT_DESCRIPTION) and the correct translation for each localized file. For example:
English file:
ADD_ITEM_SHORTCUT_TITLE = "Add";
ADD_ITEM_SHORTCUT_DESCRIPTION = "a new item";
German file:
ADD_ITEM_SHORTCUT_TITLE = "Füge hinzu";
ADD_ITEM_SHORTCUT_DESCRIPTION = "ein neues Item";
Then, go to your Info.plist and enter your key to the corresponding field. For example:
That way, you get localized UIApplicationShortcutItems. Now, they look like this:
Phone language English:
Phone language German:
Here's the scenario. I have a set of settings in an app. For example consider my app as a video player. So there are settings like allow full screen, display subtitles etc. All these settings have boolean values since you either turn on or off them.
These settings should display inside the app in a table view. And if any of them are activated or when the user taps on them to activate/deactivate, you show it by setting the checkmark accessory view of that cell.
Since I need the settings to be displayed this way and only within the app, I cannot simply use Settings bundles. There's also another catch. I need these settings to be localized.
What I initially thought was to have separate plists for the languages I support.
Settings_en.plist (English)
Settings_sv.plist (Swedish)
Then fetch the plist name depending on the system language and display its values.
let filePath = NSBundle.mainBundle().bundlePath.stringByAppendingPathComponent(NSLocalizedString("SETTINGS_PLIST", comment: ""))
But this is not ideal because say I'm running in Swedish and I change the Subtitles setting to on. Now i have to update this in both plists. This will quickly become even messier if I add more languages in the future.
Is there a better way to store settings which is easier to save and fetch and also supports localization?
I was able to find an answer elsewhere. Here are the steps taken to resolve this issue.
Instead of multiple plists, create one plist and have the keys in English language.
Then have the localized strings in your string files with the same English keys.
Localizable.strings (English)
FULL_SCREEN = "Full Screen";
SUBTITLES = "Subtitles";
Localizable.strings (Swedish)
FULL_SCREEN = "Helskärm";
SUBTITLES = "Undertexter";
In the code when you're displaying the values in a table view, refer to them by that key.
let setting = settings[indexPath.row] as [String: Bool]
let title = setting.keys.first
cell.textLabel?.text = NSLocalizedString(title!, comment: "")
I'm having trouble reading a NSLocalizedString through my English .csv file.
In my app a user comes across a UITableViewController and selects a row. Whatever that row's title is is set to a global NSString selectedRow inside a NSObject (this NSObject is imported in every class). Once this occurs the next UIViewController reads selectedRow, runs through the .csv file until it comes across it, and then vomits all the information needed onto the UIViewController.
Example: selectedRow = "About"; so in French this would be selectedRow = "Environ";
Now I don't have "Environ" in my .csv file, I have "About", so how would I force a NSLocalizedString to be English for a few moments without having to make a completely new French version of my .csv file?
If you want to use NSLocalizedString then you would need to make .string files, if your CSV is actually static and want to translate words like "About" then you can follow the instructions here to add the .string files, make one for English, one for French, then if the user is using French as the Language Setting, they will see the content in French... If your .csv is not static and it constantly changes and has full sentences, then this probably wont work, and you would probably want to use a french version of the .csv file... You can localize it as described above too..
Hope this helps
Daniel
I'm making a parser in rails for a website and I'm having trouble selecting only the stuff I want.
I want to select the following sibling to a td-tag that contains ONLY "World:", but there's another td-tag containing "Former World:" that I get too, and I don't want to select that one.
Here's my XPath selection:
//td[contains(text(), 'World:')]/following-sibling::td
So I want the tag containing ONLY "World:" and not the other one containing "Former World:"
Any ideas? Spent hours searching for a solution, but now I ended up here.
Does it work if you change it to
//td[text()='World:']/following-sibling::td
Have you tried testing the text with equals?
//td[text() = 'World:']/following-sibling::td
or
//td[. = 'World:']/following-sibling::td