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,676
  • TimeZoneExample.zip
    5.7 KB · Views: 1,822
  • DateUtilsExample.zip
    6.1 KB · Views: 1,789
  • AHLocale1_16.zip
    17.3 KB · Views: 3,743
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

Thank you, Markus, for a wonderful and extremely useful library.

I would like to report an error or a conflict, if I may.

According to ISO 4217, the Colombian peso has 2 decimal points and the AH library generates 0 decimal points.

As far as I know from research on the Web, it has always been 2 decimal points.

ISO 4217 here

Best regards.

Sandy
 

corwin42

Expert
Licensed User
Longtime User

The library is just a wrapper to native Java/Android functions so I can't do anything for this issue.
 

TomDuncan

Active Member
Licensed User
Longtime User
I need to convert from a sqlite date string which returns "2015-06-01 11:40:00 AM" from my server.
I need to convert this into a long so I can use Datetime.
We use dd/MM/yyyy so you can see my problem.

This is what I have tested.
It does say that the default is yyyy-MM-dd hh:mm:ss
But this throws an exception

B4X:
    Dim dt As AHDateTime
    dt.Initialize
    Dim d As Long = dt.Parse("2015-06-01 11:40:00 AM")

any thoughts.

Tom
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

Once more, thank you for this splendid library.

Is there a B4J version?

Thank you.

Sandy
 

corwin42

Expert
Licensed User
Longtime User
Greetings.

Once more, thank you for this splendid library.

Is there a B4J version?

No, the library uses some classes from the android framework so there is no port for B4J (and none for B4i).
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you for taking the time to reply.

B4J Could use it, specially for currency symbols and currency formats.

Best regards.
 

cimperia

Active Member
Licensed User
Longtime User
+1
 

ilan

Expert
Licensed User
Longtime User
hi corwin, can i get with your lib for a specific date and a specific country if dst is true?

like:

dim dst as boolean = checkdst("01/04/1999","London")

and i will know if at that specific date in that specific state daylight saving time was true (summer time)

is that possible?

regards, ilan
 

Cableguy

Expert
Licensed User
Longtime User
Hi @corwin42,

I'm using the lattest version of AHLocale (1.16) and found that .weekDays is returning an array of 8 strings, being that .Weekdays(0) is empty...
also happens with ShortWeekDays...

Shouldn't this be a 7 string long array?
 

DonManfred

Expert
Licensed User
Longtime User
Shouldn't this be a 7 string long array?
Probably yes when the weekdays are counted from 0 to 6. But if someone start counting at 1 instead of 0 then it is a reason to use a 8 string array with one empty with will be ignored in such situations. So the days can be accessed by 1 to 7.

Maybe the underlying library does work with 1 to 7 values for the days?

Just my two cent... Feel free to ignore when i tell bullshit
 

Cableguy

Expert
Licensed User
Longtime User

Working around this issue is indeed very simple, but, I dont think this behaviour was intended, For example, in the same lib, .Months array Is 12, as it should be...
If one creates an app based in this behaviour and then the lib gets updated or added new features, it will break existing code...
 

DonManfred

Expert
Licensed User
Longtime User
"Handling" months and daynumbers is different. In the past 30 years of programming i always saw 1 to 12 for month but i saw different behaviour for the weekdaynumbers. 0 to 6 AND 1 to 7. That´s why i thought it may be the point here...
 

Cableguy

Expert
Licensed User
Longtime User
"Handling" months and daynumbers is different. In the past 30 years of programming i always saw 1 to 12 for month but i saw different behaviour for the weekdaynumbers. 0 to 6 AND 1 to 7. That´s why i thought it may be the point here...
yes but, since it's an array.... shouldn't it assume 0 to 6 ? the lib help is almost inexistent!
 

corwin42

Expert
Licensed User
Longtime User
It is just a wrapper to DateFormatSymbols.getWeekdays()

I think the intention for the offset is that you can use the Calendar class constants as indexes.
 

Highwinder

Active Member
Licensed User
Longtime User
Corwin,

How do I properly use "InDaylightSavings" to determine if the device is in DayLight Savings mode or time zone?

I have seen no tutorial or example (or even a conversation about it) posted so far, and I would really like to see how to use it.

Thanks so much,

HW
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Just initialize a AHTimezone object with the timezone you want. Then you call AHTimezone.IsDaylightTime() with a date in ticks. If the given date is in the period where daylight savings is active the method returns true, otherwise false.
 

Alisson

Active Member
Licensed User
Hello Corwin42!
I have one question.
If change the sentence of Label, example:
"Currency" to "What is your name?" and
change english to spanish, the english change to spanish?
In my case, the sentences "what is your name?" not change.
It's correct?
I need translate one app to multilangugae!

Thanks!
 

corwin42

Expert
Licensed User
Longtime User

The library can not translate strings automatically. You will have to provide language files for the translation.
If you want to translate views created with the designer like a label, you will have to change the Label.Text attribute at runtime to set the text with the right language.

See the example project.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…