SuperCard 4.8 and Locale Information

Need help with a script? This is the place to discuss how to get your code running!

SuperCard 4.8 and Locale Information

Postby codegreen » Tue Mar 29, 2016 8:26 am

SuperCard 4.8b11 introduces several new features to simplify dealing with the ISO codes used in localization.

First there are three new global properties called the countryCodes, the currencyCodes, and the languageCodes which return complete lists of (DUH) the currently available ISO country, currency, and language codes, as well as their display names (i.e., human-readable equivalents).

Second there's a new function called locale, which returns some useful information about individual locales. It takes a locale identifier just like the one you pass to the convert command when formatting/unformatting numbers (which must include both a language code and a country code). If you just want info about the current locale, you may omit the locale identifier.

If successful the locale function returns either just a requested value, or a requested ISO code plus its display name separated by a tab.

The locale function accepts two optional parameters, a keyword and a locale. If no keyword is passed it defaults to identifier. In order to pass the locale you must also supply a keyword. This must be one of:

identifier - returns the locale identifier and display name

calendar - returns the name of the calendar for the locale

country - returns the country code and display name for the locale

currency - returns the currency code and display name for the locale

currencySymbol - returns the currency symbol for the locale

decimalSeparator - returns the decimal separator for the locale

groupingSeparator - returns the grouping (i.e., 'thousands') separator for the locale

measurementSystem - returns the measurement system (U.S. or Metric) for the locale

For example, in the USA:

Code: Select all
put locale()                    -- en_US   English (United States)
put locale(identifier)          -- en_US   English (United States)
put locale(calendar)            -- gregorian   Gregorian Calendar
put locale(currency)            -- USD   US Dollar
put locale(currencySymbol)      -- $
put locale(decimalSeparator)    -- .
put locale(groupingSeparator)   -- ,
put locale(measurementSystem)   -- U.S.

put locale(identifier, fr_FR)          -- fr_FR   French (France)
put locale(calendar, fr_FR)            -- gregorian   Gregorian Calendar
put locale(currency, fr_FR)            -- EUR   Euro
put locale(currencySymbol, fr_FR)      -- €
put locale(decimalSeparator, fr_FR)    -- ,
put locale(groupingSeparator, fr_FR)   --  
put locale(measurementSystem, fr_FR)   -- Metric

I debated rolling the global props into the locale function itself, but couldn't decide whether the reduced footprint justified further overloading locale with more keywords. I'm curious to know what users think about that, so please don't hesitate to speak up if you think one version or the other would be better for some articulable reason…

I stuck a simple demo project called FormatFunHouse.sc45 up in the Files section that contains some examples of how to use these things.

Enjoy!
-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Return to Scripting in SuperTalk

Who is online

Users browsing this forum: No registered users and 1 guest

cron