B4A Library AHLocale library

With this library you can convert dates, timestamps, numbers and normal texts to the format your device uses. You can even translate your apps to different languages.

The AHLocale object provides many information about your devices locale settings like Currency symbol, month names, weekday names etc.

The AHTranslator object provides methods for creating multilanguage apps.

The AHDateTime object provides methods for formatting and parsing date strings. The internal DateTime object of B4A has the problem that it uses localized format identifier so it is not possible to parse a date string in the format "2011/05/19 12:15 AM" on a german device because the "AM" is "vorm." on it. With the AHDateTime object you can parse and format dates in any locale.

The AHTimeZone object provides methods to get information about timezones (like offset to UTC, DST offset etc.)

The AHDateUtils object provides methods to format dates and date ranges and display them localized.

The AHNumeric object provides methods to handle different (localized) number formats.

The example app starts always in english. Translation files for german, italian and japanese are provided. Try to select another language with the topmost spinner and see how the language of the user interface changes.


History:
V1.1:
  • fixed Documentation
  • fixed some bugs (DisplayXXX methods)
  • new AHDateTime object
  • some minor improvements

V1.11:
  • fixed problem with AvailableLocales not working on all devices

V1.12:
  • new AHTimeZone object to get information from timezones

V1.13: (never released)
  • Add TimeZone property to AHDateTime object

V1.14:
  • AHTranslator.java - Removed log output
  • Timezone.java - fixed type

V1.15:
  • AHDateUtils object - new
  • AHNumeric object - new
V1.16:
  • AHDateTime - Methods for getting default date and time format strings
  • AHTranslation - Support for Countries
  • AHTranslation - Support for default language
  • AHTranslation - Support for different file extensions
 

Attachments

  • LocaleExample.zip
    8.3 KB · Views: 3,678
  • TimeZoneExample.zip
    5.7 KB · Views: 1,827
  • DateUtilsExample.zip
    6.1 KB · Views: 1,791
  • AHLocale1_16.zip
    17.3 KB · Views: 3,746
Last edited:

Arf

Well-Known Member
Licensed User
Longtime User
This has been working well for me with French, Dutch, Serbian, Polish but it is not working for Russian - which I am desperate to get working for a demo on friday!

All my files seem correct, and the only difference between the working Polish for example and Russian is the '4' in the unicode throughout the Russian input file, for example:
Polish:
EXIT=WYJ\u015aCIE
Russian:
EXIT=\u0412\u042b\u0425\u041e\u0414

Polish displays as
WYJŚCIE
Russian just returns the English string.

If I paste the unicode in the Russian lng file into the convertor @corwin42 linked to, it says it should come out as
ВЫХОД

Any idea what I could try? Thanks
 

Arf

Well-Known Member
Licensed User
Longtime User
The codes are definitely correct. The most likely thing I can think of is that the font you are using does not include the Cyillic code page.
Mmm, at no point in my project do I define what font is used - they are are just whatever B4A has always used by default.
 

agraham

Expert
Licensed User
Longtime User
I don't understand the meaning of that reply. Whatever the font is and however it was selected it looks like it does not support Cyrillic characters. What device are you using it on. I would have expected that most Android devices do support Cyrillic.

Try this fragment on your device, it displays correctly on both of my devices that I tried it on, I can't be bothered trying the other four.
B4X:
Sub Button1_Click
    Dim cs As String = Chr(0x042b) & Chr(0x0425) & Chr(0x041e) & Chr(0x0414)
    xui.MsgboxAsync(cs, "Cyrillic")
End Sub
 

Arf

Well-Known Member
Licensed User
Longtime User
I just use whatever font B4A uses by default, I have never changed it, set it or even know where it is set!
If i look in the visual designer at a button for example, the TYPEFACE is set to DEFAULT.
Does it come from the theme setting? In which case that is Holo.Light in the manifest.

Anyhow that doesn't seem to be the issue as I just tried the XUI snippet and I am seeing 'ВЫХОД' on screen.

So i guess the issue is inside the AHLocale library somehow :-(
 

Arf

Well-Known Member
Licensed User
Longtime User
Solved, I'm an idiot - I dropped the lng into the Files folder in Windows Explorer but failed to add it to Files in B4A!
Working now, thanks for your time.
 

Arf

Well-Known Member
Licensed User
Longtime User
If I build my app with targetSDK=33 and install it on a Android 13 device for the first time, translations didn't work.
I was getting some error indicating that the Map was not accessible, I thought it was maybe something to do with External Access not being available (I am doing everything in DirInternal now), even though I believed that this lib only needs the files in DirAssets.

Anyhow, it all started working fine when I commented out the #DebuggerForceStandardAssets: true in my main module.
Not sure why, as I have been working in Release all day, not Debug.

Maybe this helps someone with a similar issue.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…