Get current input language on android (Xamarin) - xamarin.android

Is there any way to get current input language?
I've tried this:
editText_input.TextLocale
but it returns default system language. Also I tried to look into
Android.Views.InputMethods.InputMethodManager
but no luck as well. Any suggestions?

It seems you could only get the keyboard language by using:
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
InputMethodSubtype ims = imm.CurrentInputMethodSubtype;
string localeString = ims.Locale;
For example:

Related

How to localize the Autodesk Forge Viewer DiffTool extension

We are using the Autodesk Forge Viewer DiffTool extension, but we need to change one of the texts:
Every tutorial shows how add localization to your own extension, but I couldn't find how to change a translation in an existing extension you are using.
Moreover, without knowing what the translation key is, I would have "guess" it, which isn't really great either.
So, how do I change the translation for this text?
There is no supported way to hook into the translation service of the Viewer to change the text. If the translation is wrong, please let us know, and we can fix that on our side.
If you want to change the text for some other reasons, then one thing you could do is wait for the initialization of the extension's UI and change the button's content using DOM APIs:
let extensionConfig = {}
extensionConfig['mimeType'] = 'application/vnd.autodesk.revit'
extensionConfig['primaryModels'] = [model1]
extensionConfig['diffModels'] = [model2]
extensionConfig['diffMode'] = 'overlay'
extensionConfig['versionA'] = '2'
extensionConfig['versionB'] = '1'
extensionConfig['onInitialized'] = () => {
let button = document.getElementById("diffFacetsRemovedButton");
let label = button.nextSibling;
label.innerHTML = label.innerHTML.replace("Odebrat", "Něco jiného");
}
viewer.loadExtension('Autodesk.DiffTool', extensionConfig);

How change app language in real time?

I am working on an app which runs in 2 languages, English and Persian (farsi). So user can select his desired language and app is displayed in that language. What should I do?
Depends on what are your trying to achieve, there is an approach that might be useful to your case, which is:
Declare a global variable which should represents the key of the current used language in the app, call it appLanguageKey String -for example-:
var appLanguageKey = "english"
Create a datastore for storing both languages desired caption for each term, it might looks like (contains):
term_key term_english term_farsi
greeting_key Hello Hoi
bye_key Bye Doei
For now, you could get the desired value if you tried to do:
desiredTerm = "select term_\(appLanguageKey) where term_key = 'greeting_key'"
Consider it as pseudo-code, the condition should be similar to it.
By implementing such a function that returns a string (I will assume that it is: getDesiredCaption(_ termKey: String) -> String in the following code snippet), you will be able to automatically set the desired caption for any UI component, just call it in viewWillAppear method the view controller:
override func viewWillAppear(_ animated: Bool) {
.
.
.
label.text = getDesiredCaption("greeting_key")
// Since that 'appLanguageKey' global viriable is "english",
// the output should be "Hello"
.
.
.
}
All you have to do for changing the language of the app is to change the value of appLanguageKey to "farsi".
For another approach which related to the Internationalization and Localization, you might want to check this answer, it should affect the app to let its navigation to be from right to left.
Hope this helped.
First you should use realm, magical records or an API to store what the user picks. Then you could create your own type of localizeable string handeler, by having an array with 2 dictionaries 1 with english and 1 with persian that all the texts in your application will read from just as you do with a normal localizeable.

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.

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

TAction.SecondaryShortCuts is language specific. How to set it correctly?

I just used the SecondaryShortCuts-Feature of Delphi's TAction. But Shortcuts are defined by Strings, like "F5" or "Shift+F5". Now the problem: On my German Windows the action doesn't fire, because the key "Shift" is called "Umsch" in German!
Does it mean the SecondaryShortCuts-Property is completely useless at design time, because nobody can create applications which work internationally with that?
I could set the key at runtime by translating the VK_SHIFT into the correct name. I tried it via GetKeyNameText but this didn't worked because it gave the long form "Umschalt" not "Umsch". Anybody know the function to get the short version of the key name?
You could try this: Generate the shortcut text from a shortcut:
var
s: TShortCut;
begin
s := ShortCut(Ord('A'), [ssShift]);
Action1.SecondaryShortCuts.Add(ShortCutToText(s));
By the way, these values are determined by the following constants. Have you translated those? And if so, do you need to?:
SmkcShift = 'Shift+';
SmkcCtrl = 'Ctrl+';
SmkcAlt = 'Alt+';

Resources