libphonenumber ios get country code for country - ios

Given a country, how do I get the countryCode? The following method is not working
NSNumber* code = [phoneUtil getCountryCodeForRegion:country];

It is working, I used it like so:
[phoneUtil getCountryCodeForRegion:#"US"]
and the output was 1.
Note that you have to use the ISO Country Code, 2 Digit: "US", (you can find a list here).

Related

How can I get the variant of the language on ios?

I have my Iphone set to English (UK) and I am trying to get the UK part in my flutter ap by doing this.
final languageCode = Platform.localeName.split('_')[0]; //prints en
final countryCode = Platform.localeName.split('_')[1]; //prints NL where I want UK
But my country code is alway NL which is my region. How can I get UK?
Its look like you want to access ISO Country Code
You can acces your device language country code with :
//Your device's all locales
final List<Locale> systemLocales = WidgetsBinding.instance!.window.locales;
//Your device's first(current) locale country code.
String? isoCountryCode = systemLocales.first.countryCode;
Following are the 3 ways I know to get locales:
Localizations.localeOf(context);
WidgetsBinding.instance.window.locale;
Platform.localeName;
Make sure to have the supportedLocales correctly setup in your MaterialApp which is only en_US by default, in order to have all available locale.
supportedLocales: [
const Locale('en', 'UK'),
const Locale('fr', 'CA'),
],
You may need to import and add to your pubspec.yaml 'package:flutter_localizations/flutter_localizations.dart';

How to retrieve a value for NSLocale .scriptCode in Swift

I'm trying to print some basic infos from NSLocale, but I'm not able to get a value back from the .scriptCode property.
Currently, the relevant bits are
let localeIdent = NSLocale.autoupdatingCurrent.identifier
let userLocale = NSLocale(localeIdentifier: localeIdent)
let languageScript = userLocale.scriptCode //not sure why this doesn't seem to return anything.
print("Language script code: \(languageScript)")
the print always returns 'nil'.
The locale returns the rest of the set of information for me, region and language and such, so I'm not sure why this wouldn't be stored / returning.
Not all locales have a script code. See the Language and Locale IDs section of the Internationalization and Localization Guide.
Locale identifiers can contain various parts such as the language code, script code, and region code. The script and region codes are optional.
Look at the documentation for Locale scriptCode for an example:
For example, for the locale “zh-Hant-HK”, returns “Hant”.
Simpler locales such as en_US or de_DE don't have a script code.

Java API which return language code from language display name

I have a service which gives the language display name as part of response. I want to retrieve the language code so that I can apply the internationalization for output file.
Expected input : English - United States
Output : en_US
You might use something like that:
Optional<Locale> locale = Arrays.stream(Locale.getAvailableLocales())
.filter(l ->
l.getDisplayLanguage().equals("English") &&
l.getDisplayCountry().equals("United States")
).findAny();
locale.ifPresent(System.out::println);

Objective-C iOS parse string according to the definition

I want create an iOS app for my school.
This App will show Week schledule and when I tap on Cell with Subject, it will show me detail info about subject...
My problem:
Our teachers use shotcuts for their names, but I want show their full name... I created the file "ucitele.h" with definitions of their names, but I don't know, how to use it 😕.
This is how that file looks:
//
// ucitele.h
//
#define Li #"RNDr. Dan---vá"
#define He #"Mgr. Ja---hl"
#define Sm #"Ing. Mich---rek"
#define Ks #"Mgr. Svat---á"
I get the shortcut of Teacher from previous view from "self.ucitel" and I maybe want compare the contents of the "self.ucitel" with definitions and set the "ucitelFull" string from the definitions? I don't know how to say it 😕.
when the content of the self.ucitel will be #"Sm", than I want parse "ucitelFull" as #"Ing. Mich---rek"
Answers in Objective-C only please
Okay, sounds like your trying to map a short identifier to a full name:
-(NSString*)fullNameFromShortName:(NSString*)short {
NSDictionary * names = #{#"Li" : #"RNDr. Dan---vá",
#"He" : #"Mgr. Ja---hl", ... };
return [names objectForKey:short];
}
Use like:
self.ucitelFull = [self fullNameFromShortName:self.ucitel];
This is a dictionary that has the short name as a key and the full name as the value.
Some further suggestions:
try using lowercase keys and comparing lowercaseString's, incase the user doesn't enter the value with the correct case.
You can move the dictionary definition into a json file and read it from your bundle, to eliminate the hardcoding

Convert ISO2 country code

My goal is to concert a code like 'CH' in Switzerland , I want to convert it in the language of the locale of the users browser
I tried to use the country tag provided by grails:
<g:country code="che"/>
But it seems working only with IOS3 codes.
Anyone can help me?
Thanks in advice.
You can use the java.util.Locale instance yourself
def l = new Locale('de', 'CH')
l.displayCountry // will display `Switzerland` on a computer with English locale
l.getDisplayCountry(l) // will display `Schweiz`
l.getDisplayCountry(request.locale) // the answer to your question

Resources