How to use Globalize 1.0 and get the specified culture information

How to use Globalize 1.0 in html web application.

I need to get the following information using Globalize 1.0 support

  • How to create a simple sample with support for Globalize 1.0.

  • How to get default currency symbol and percentage symbol using Globalize 1.0 support and dynamic symbol change

  • How to get a positive / negative template for Currency / Percentage value of a specified culture and dynamic template change

  • How to get the default date format for a specified culture.

  • How to get the default group separator and decimal separator for the specified culture

If you have any samples or code snippet for the problem, then please share it.

if possible share a simple sample with Globalize 1.0

Thanks.....

Gobala

+7
javascript globalization javascript-globalize
source share
1 answer

Quick and recommended way :

Now, right to your questions:

  • How to create a simple sample with support for Globalize 1.0.

Assuming you want to play with globalization locally, I recommend using Node.js:

npm install globalize cldr-data node var Globalize = require("globalize"); # Feed Globalize on CLDR data Globalize.load(require("cldr-data").entireSupplemental()); Globalize.load(require("cldr-data").entireMainFor("en"); Globalize("en").formatNumber(Math.PI); // > '3.142' Globalize("en").formatNumber(Math.PI, {maximumFractionDigits: 2}); // > '3.14' Globalize("en").formatCurrency(69900, "USD"); // > '$69,900.00' Globalize("en").formatCurrency(69900, "EUR"); // > 'โ‚ฌ69,900.00' Globalize("en").formatRelativeTime(-35, "second"); // > '35 seconds ago' 

I answered your 1st question here? Just let me know if you meant anything else.

  1. How to get default currency symbol and percentage symbol using Globalize 1.0 support and dynamic symbol change

If you do not know the currency, how do you know the correct monetary value and corresponds to what is formatted / displayed?

Specifications (UTS No. 35) clearly do not report the availability of currency in the country. "Note: currency values โ€‹โ€‹should never change without a known currency code. You never want the number 3.5 to be interpreted as 3.50 US dollars per user and 3.50 euros for another. These locales contain localization information for currencies, and not the currency value for the country. The currency amount logically consists of a numerical value plus an accompanying currency code (or equivalent). The currency code may be implicit in the protocol, for example, where the dollar is implicit. But if the raw numerical value is transmitted without any context that does not have a final interpretation. "

http://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies

Please note that applications can use CLDR to display the currency used in the country in a certain period of time, and then submit it for the currency Formatter. See How to access culture data in globalize.js V1.0.0 for access to CLDR data.

  1. How to get a positive / negative template for Currency / Percentage value of a specified culture and dynamic template change

Can you give an example of the changes you want to make? Does the example below help?

 Globalize("en").formatNumber(0.5, {style: "percent"}); // > '50%' Globalize("en").formatNumber(-0.5, {style: "percent"}); // > '-50%' Globalize("en").formatNumber(-0.5, {style: "percent", minimumFractionDigits: 2, maximumFractionDigits: 2}); // > '-50.00%' Globalize("en").formatCurrency( -69900, "USD" ) '-$69,900.00' 

Note. Glossalization will handle the appropriate default values โ€‹โ€‹for you, for example, in Arabic:

 Globalize("ar").formatNumber(-0.5, {style: "percent"}) // > 'โ€-ูฅู ูช' 
  1. How to get the default date format for a specified culture.

Please, could you provide a precedent? I donโ€™t understand what you are trying to accomplish.

The default date format is numeric year, month, and day, i.e. the same as Ecma-402 Intl.DateTimeFormat https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

You can override the default value as you wish using the date format options.

  1. How to get the default group separator and decimal separator for the specified culture

Please, could you provide a precedent? I donโ€™t understand what you are trying to accomplish.

In any case, see How to access culture data in globalize.js V1.0.0 on how to access CLDR data directly.

+3
source share

All Articles