B4J Question get OS language

red30

Well-Known Member
Licensed User
Longtime User
How can I get windows language? B4A has the "AHLocale" library. With the query "loc.Language" I can find out the current language of the system Android. Is it possible to do this somehow in B4J?
 

inakigarm

Well-Known Member
Licensed User
Longtime User
How can I get windows language? B4A has the "AHLocale" library. With the query "loc.Language" I can find out the current language of the system Android. Is it possible to do this somehow in B4J?
From Localizator.bas (https://www.b4x.com/android/forum/threads/b4x-localizator-localize-your-b4x-applications.68751/)
B4X:
Private Sub FindLocale As String
    #if B4A or B4J
        Dim jo As JavaObject
        jo = jo.InitializeStatic("java.util.Locale").RunMethod("getDefault", Null)
        Return jo.RunMethod("getLanguage", Null)
    #else if B4i
    Dim no As NativeObject
    Dim lang As String = no.Initialize("NSLocale") _
        .RunMethod("preferredLanguages", Null).RunMethod("objectAtIndex:", Array(0)).AsString
    If lang.Length > 2 Then lang = lang.SubString2(0, 2)
    Return lang
    #end if
End Sub
 
Upvote 0
Top