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,679
  • TimeZoneExample.zip
    5.7 KB · Views: 1,827
  • DateUtilsExample.zip
    6.1 KB · Views: 1,791
  • AHLocale1_16.zip
    17.3 KB · Views: 3,749
Last edited:

agraham

Expert
Licensed User
Longtime User
Shows 1.10 for me. Have you either quit and restarted the IDE since adding the latest library or done a right-click -> Refresh on the Libs tab?

Alternatively have you added the latest library and xml to the Basic4android Libraries folder but still have the old version in your Additional libraries folder?
 

bluedude

Well-Known Member
Licensed User
Longtime User
AHLocal

agraham,

restarted multiple times, have done refresh multiple times and have no additional libraries folder. All is in my Libraries folder.

Have an old version in a complete other directory (have multiple B4A versions) so that isn't the problem.

So it is a weird problem.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Old version

Don't know why but removed the libraries from my very old B4A version and now it shows up in v 1.10 in my new B4A. Very weird.
 

Cableguy

Expert
Licensed User
Longtime User
I need help from you GURUs....

How do I set a multi line text?

Something like:

Text = This is the Text
This is a second line

P.S: I am using 'Text = Texto' for the translations and is working fine even with multi word frases.
 

corwin42

Expert
Licensed User
Longtime User
How do I set a multi line text?

Something like:

Text = This is the Text
This is a second line

Try using

Text = This is the Text\nThis is a second line
 

Cableguy

Expert
Licensed User
Longtime User
I already did,

This is the text\ this is a second line of text gives me a single concatenated line!
This is the text\nthis is a second line of text gives me only the fisrt sentence up to the \

PS: Its works with your suggestion, I had an extra (?) crlf seperating the two text lines, so I think I cannot do:

This is 1 line\n
this is 2 line\n
This is 3 line

??
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Ok, so now I found a way to keep it clean.

I can use this scheme:

This is line 1\
\n This is line 2\
\n This is line 3
 

jo1234

Active Member
Licensed User
Longtime User
Hi Markus,

thanks for the great lib. That helps a lot. :sign0098:

However, as I understand it, only strings that have been used are stored in the missing translation list.

But what about strings that have not been used (like error messages)?
Moreover, I have to implement a call to WriteTranslation, each time I want to get the list of missing translations.


I think it would be great to have separate program, which scans the .b4a and .bas files for "GetText" and creates for each of them a .properties file with all strings following a "GetText".
This way, you could easily update your translations and be sure that you caught all strings that need to be translated.

Is that something you could consider writing?

thanks again for the great lib,
Johannes

BTW: What resource editor do you recommend to do the translations?
I tried the 'DOKSoft Properties Editor', which is ok.
 

corwin42

Expert
Licensed User
Longtime User

Yes, the missing translations are checked and gererated if you call one of the GetText() functions. This whole mechanism and the WriteTranslation functions are intended for helping the developer to create the properties files.
I know that this is not perfect this way but it's better than nothing.


This is a nice idea but unfortunately I don't have the time to write such a program.

I can't make any suggestions for a properties editor because I currently don't use one but if you find a good free one, feel free to post it here.
 

COBRASoft

Active Member
Licensed User
Longtime User
I get a crash on line 57:
For i = 0 To locale.AvailableLocales.Size - 1

Any idea?
 

COBRASoft

Active Member
Licensed User
Longtime User
Sorry it took so long, here are the logs... I hope this will help.

** Activity (main) Create, isFirst = true **
GC_CONCURRENT freed 1458K, 57% free 2962K/6791K, external 2091K/2133K, paused 4ms+2ms

FileName:LocaleExample_en.lng

Pattern: yyyy-MM-dd HH:mm:ss

2012-01-28 18:46:07
05/19/2011

00:45:00
GC_CONCURRENT freed 361K, 51% free 3350K/6791K, external 2091K/2133K, paused 1ms+2ms

Error getting ICU gregorian resource bundle: U_MISSING_RESOURCE_ERROR

Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x2aac8578)

FATAL EXCEPTION: main
java.lang.AssertionError: couldn't initialize LocaleData for locale th_TH_TRADITIONAL
at com.ibm.icu4jni.util.LocaleData.initLocaleData(LocaleData.java:322)
at com.ibm.icu4jni.util.LocaleData.makeLocaleData(LocaleData.java:128)
at com.ibm.icu4jni.util.LocaleData.get(LocaleData.java:103)
at java.util.Calendar.<init>(Calendar.java:724)
at java.util.GregorianCalendar.<init>(GregorianCalendar.java:338)
at java.util.GregorianCalendar.<init>(GregorianCalendar.java:314)
at de.amberhome.AHLocale.init(AHLocale.java:36)
at de.amberhome.AHLocale.getAvailableLocales(AHLocale.java:81)
at de.amberhome.localeexample.main._activity_create(main.java:279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at de.amberhome.localeexample.main.afterFirstLayout(main.java:84)
at de.amberhome.localeexample.main.access$100(main.java:16)
at de.amberhome.localeexample.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity de.amberhome.localeexample/.main
Activity pause timeout for HistoryRecord{2aff1790 de.amberhome.localeexample/.main}
 

RiverRaid

Active Member
Licensed User
Longtime User
\n?

Hi!

First of all: Thanks for your great library!!!!!

I use:
B4X:
InfolblErstelltVon.Text = trans.GetText2("{1}{2}\n crlf Version {3}\n\nCopyright © 2012 me",Array As String(PhonePackageManager.GetApplicationLabel("com.com.com"),tmpDonateText,PhonePackageManager.GetVersionName("com.com.com")))
but the library is not interpreting the "\n" as new line...
Am I doing something wrong, or do i have to find an other way?

Thanks!
 

corwin42

Expert
Licensed User
Longtime User
I think you will have to use something like

B4X:
trans.GetText2("{1}{2}" & CRLF & "Version {3}" & CRLF & CRLF "Copyright � 2012 me",Array As String(PhonePackageManager.GetApplicationLabel("com.com.com"),tmpDonateText,PhonePackageManager.GetVersionName("com.com.com")))
 

sigster

Active Member
Licensed User
Longtime User
Hi

I try your Sample I have Icelandic Language in my mobile
it don't show up in spinner

Regards
Sigster
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…