How to determine the OS language

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Posts: 73
Joined: Wed Dec 14, 2022 1:13 pm

How to determine the OS language

Post by AZJIO »

How to determine the OS language.
I found this code but it doesn't work for me.

Code: Select all

Procedure GetLocale()
! var localeos = Locale.getDefault().getLanguage();
; ! return (localeos);
! return (lang.contentEquals("ru"));
EndProcedure
Debug GetLocale()
although I have only tried it on the browser, not on the phone.
plouf
Posts: 196
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: How to determine the OS language

Post by plouf »

the closest and accurate enough you can et is browser languange

Code: Select all

!var v_browserfirstlanguange = navigator.language;
!var v_browseralllanguanges = navigator.languages;
Debug BrowserFirstLanguange
Debug BrowserAllLanguanges
Christos
AZJIO
Posts: 73
Joined: Wed Dec 14, 2022 1:13 pm

Re: How to determine the OS language

Post by AZJIO »

Thanks, I made some interesting examples

Code: Select all

EnableExplicit

Global NewList MonthL.s()
Global lang0$, lang$
Global i, weekday$
Global Dim Lng.s(3)

Lng(1) = ": loading error"
lang$ = "en"

!var v_lang0$ = navigator.language;
If lang0$ = "ru-RU"
	Lng(1) = ": ошибка загрузки"
	lang$ = "ru"
EndIf

! for (var i = 0; i < 12; i++) {
If AddElement(MonthL())
	! t_MonthL.current._s = i + 1 + '\t' + new Date(0,i).toLocaleString(v_lang$, { month: 'long' });
EndIf
! }

; For i = #txtLast To #txtLast + 6
For i = 1 To 7
	! v_weekday$ = new Date(0, 9, v_i).toLocaleString(v_lang$, { weekday: 'short' });
	Debug weekday$
Next

ForEach MonthL()
	Debug MonthL()
Next
Post Reply