I have localizable English and French. I want display Registered symbols as a part of word i.e "MyApp®". English part of localization file shows this symbol correct in iOS APP UI. Same needs to display for French version i.e "MyAppᴹᴰ" but space comes in between 'M' and 'D'.
I also tried using unicode like MyApp\u{1D39}\u{1D30}. This gets worked in Swift playground but if I try it through Localization file it doesn't work.
iOS version: 11.4
I need to make changes in localization file only and not to use NSAttributed string every where in code.
If anyone came across same problem, and found solution please post.
"MyApp®" = "MyApp\u{1D39}\u{1D30}" // Localization file
print(String(describing: "MyApp\u{1D39}\u{1D30}" // swift playground
print(String(describing: "ᴹᴰ")) // swift playground
"MyApp®" = "MyApp\u{1D39}\u{1D30}" // Localization file
"MyApp®" = "MyAppᴹᴰ" // Localization file- on UI space comes b/w ᴹ and ᴰ
print(String(describing: "MyApp\u{1D39}\u{1D30}")) // swift playground
print(String(describing: "ᴹᴰ")) // swift playground
"MyApp®" = "MyApp\u{1D39}\u{1D30}" // Localization file
On iOS app UI component should render MyApp® as MyAppᴹᴰ and no space between ᴹ and ᴰ.
Instead of using the separate superscript ᴹ and ᴰ characters, why not use the actual 🅫 (U+1F16B) character?
In your localization file, put:
"MyApp®" = "MyApp🅫"
Related
I have an iOS app with a default language (English).
It also has a French localization and works as expected in both languages.
Here is the problem I am having:
When setting the device to a language other than English(default) or a language for which localization is provided (for example setting the device to Japanese); the app does not fall as expected in the default language. But it keeps the last language used for the app.
Why is that? And how can I fix it?
I have found a few post with a similar issue, but the solutions proposed did not work for me. For example this one, where the problem is similar to mine.
I am using Xcode version 11.1 and iOS version 12.4.2.
iOS will have a list of preferred language order based on the previously selected languages.
So, if you changed from English then to an unmapped language (e.g ko), the application will have as AppleLanguages the array:
[ko-(ZoneCode), en-(ZoneCode)].
You can avoid this procedure using this code below:
let defaultCultureCode: String = "en"
let defaults = UserDefaults.standard
let currentAppleLanguages = defaults.stringArray(forKey: "AppleLanguages")
if let currentLanguages = currentAppleLanguages {
if(!currentLanguages.isEmpty && !(currentLanguages.first?.contains(["en", "fr"]))!) {
defaults.removeObject(forKey: "AppleLanguages")
defaults.set([defaultCultureCode], forKey: "AppleLanguages")
defaults.synchronize()
}
}
I used this string extension to check if the current languages contain the available language:
extension String {
public func contains(_ elements: [String]) -> Bool {
var haveElementOnString = false
if elements.count == 0 { return false }
else { elements.forEach{ element in haveElementOnString = haveElementOnString || self.contains(element)} }
return haveElementOnString
}
}
The next step it's up to you to define the best strategy.
In my application context, it will always be defined as English by default because it is the only .strings file available. All the other supported strings will be downloaded and then a message will be displayed to the user warning that new languages are available and will be applied next time.
There's a lot of information on StackOverflow about bundle.localizedStringForKey or NSLocalizedString that could help you to found the best solution for what you need.
Also, this is only the validation and update for the current locale and the default language. this doesn't include the Region section (e.g. ko-KR (KR)).
I found an interesting text on this topic that could be useful
How not to do localization.
I hope it solves your problem!
I'm pretty new to Fastlane and love the idea of Snapshot, but I got a little problem.
When I'm trying to create a new set of screenshots I'm facing the problem that the UITests don't use the correct localized Strings to fetch the UI elements.
My current state is based on this Stack entries: XCode 7 UITests with localized UI
The localization method:
func localizedString(_ key: String) -> String {
let uiTestBundle = Bundle(for: MyUITests.self)
return NSLocalizedString(key, bundle: uiTestBundle, comment: "")
}
Trying to perform a tap that way:
app.navigationBars[localizedString("key_1")].buttons[localizedString("key_2")].tap()
The error I get is the following:
No matches found for "Rolling stone" NavigationBar
Rolling stone is the Base/English Localization of the key, but there should be a German one. So for any reason the UITest always picks the English Localization.
Does anybody have an idea how to troubleshoot this? I checked the SnapshotHelper and it passes a "de-DE" as the language, so that's not the point.
But I just can't find the Bug :(
Localization
This link here should be sufficient enough to solve your problem. You simple pick the correct language option during the test tab under edit scheme option.
I have an app that I'd like to be able to get the localized string for a certain key, regardless of what my current localization on the iPhone is.
I have the following in an en.lproj localized strings file
"Black" = "Black";
In the es.lproj localized strings file I have
"Black" = "Negro";
So what I would like to do is get the Spanish string when my phone is in the US and set up accordingly
I'm using the following code:
let bpath:String = NSBundle.mainBundle().pathForResource("es", ofType: "lproj")! as String
let bundle = NSBundle(path: bpath as String)
let thisWord="Black"
let ourWord=NSLocalizedString(thisWord, bundle: bundle!, comment: "")
I'm expecting to get "Negro" in the value for ourWord, but I always get "Black"
Am I missing something obvious?
Localization settings apply based on the settings you set in your phone not the location. If your phone is setup to display an Application Language of Spanish then you will see the appropriate string. To configure Application Language settings so you can test this you need to edit your Scheme.
In Xcode 7.1+ Goto Product > Scheme > Edit Scheme
Then change the Application Language and/or Region to simulate what a user would see who has an iPhone configured for a region or language other than English in the US.
(Switch it to Spanish and then debug the app on the device again to see the updated localized strings).
Actually my code works fine. I had made the stupid mistake of not setting the "Localizable.strings" file as localized.
Feeling pretty dumb right now
I'm trying to use LRM in order to make a string properly displays in arabic. My string is as follows:
Percentage is: 32.12%
However on arabic it displayed as:
%32.12 :نسبة ط
So far so good. On objective-c I've used in the past following markup to fix this problem:
[NSString stringWithFormat:#"\u200E %#", value]
But when I try it on Swift it just didn't move the percent:
"\u{200E}\(value)"
Am I using unicode characters wrong in Swift or I made mistake somewhere else?
The below should be a comment on the question, really, but I need the formatting...
I do this in a Playground (Xcode 7 beta 4)
let value = "32.12%"
print("نسبة ط:\u{200E}\(value)")
And it prints
32.12% :نسبة ط
Is that what you want?
Also
let value = "\u{200E}32.12%"
print("نسبة ط:\(value)")
works the same. This is in the Playground. Are you using an older version of Xcode perhaps?
I'm trying to use FontAwesome on my ios app (ios8, xcode6), and am having trouble. I've downloaded the font, tried the TTF and OTF versions separately. I've included the font name in my plist file, and have included the NSString+FontAwesome and UIFont+FontAwesome categories that are standard out there.
The problem is that every font awesome symbol showing is always this same one. Everything works, it just never changes the character.
id github = [NSString fontAwesomeIconStringForEnum:FAGithub];
id twitter = [NSString fontAwesomeIconStringForEnum:FATwitter];
label1.font = [UIFont fontWithName:kFontAwesomeFamilyName size:32.f];
label1.text = [NSString stringWithFormat:#"%# %#", github, twitter];
If I use the unicode string directly instead of the helpers, it is still always the same
#"\uf001"
#"\uf002"
// etc
When I debugged the category classes and printed out the unicode array with all the font-awesome codes in the console, all the symbols were identical to the ones above.
[NSString fontAwesomeUnicodeStrings]
Has anyone seen this problem of the repeating symbol, or know a resolution?
EDIT
2 weeks later, after fixing by re-install: I believe the symbol shown is, which was always the same, is the result of the label's font either not being set correctly to FontAwesome, or the font not being loaded so it is not able to be set. That is the symbol that shows up when font is set to something like "System".
Steps taken for this to work:
File > Add File > Added ios-fontawesome in it entirety (copied folder)
Removed all .m files from fontawesome besides NSString+FontAwesome.m from compile sources
Added FontAwesome.tff to info.plist key Fonts Provided By Application
(Compiled for iPhone 5s Sim, 8.1 using XCode 6.1.1)
Test project listed here: https://github.com/spacedrabbit/StackScratchPad
As the comments indicate, this doesn't explain why it wasn't working it just is the way I was able to make it work.