admin管理员组

文章数量:1420159

How to use Globalize 1.0 in html web application .

I need to get the below information using Globalize 1.0 support

  1. How to create simple sample with Globalize 1.0 support.

  2. How to get the default currency and percentage symbol using Globalize 1.0 support and how to change the symbol dynamically

  3. How to get the Positive / Negative pattern for Currency/Percentage value of the specified culture and how to change the pattern dynamically

  4. How to get the default date format of the specified culture.

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

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

if possible share the simple sample with Globalize 1.0

Thank you.....

Gobala

How to use Globalize 1.0 in html web application .

I need to get the below information using Globalize 1.0 support

  1. How to create simple sample with Globalize 1.0 support.

  2. How to get the default currency and percentage symbol using Globalize 1.0 support and how to change the symbol dynamically

  3. How to get the Positive / Negative pattern for Currency/Percentage value of the specified culture and how to change the pattern dynamically

  4. How to get the default date format of the specified culture.

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

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

if possible share the simple sample with Globalize 1.0

Thank you.....

Gobala

Share Improve this question asked Jun 30, 2015 at 5:46 GopalaKrishnan subramanianGopalaKrishnan subramanian 2494 silver badges12 bronze badges 6
  • I will provide you a better answer when I find time. For now, I just wanted to make sure you have seen github./jquery/globalize/tree/master/examples – Rafael Xavier Commented Jun 30, 2015 at 15:44
  • i have download and run the sample but it doesn't run plain javascript sample and also in that sample static data can be loaded but i want to load the dynamic culture JSON data , i want to know how to load the culture data dynamically..?? – GopalaKrishnan subramanian Commented Jul 1, 2015 at 4:19
  • Here github./jquery/globalize/blob/master/doc/…, it's presented various ways of loading CLDR data (including dynamic ways). – Rafael Xavier Commented Jul 1, 2015 at 11:52
  • Hi Rafael,thanks for your update.. the above mentioned sample works only when i host the sample in IIS otherwise not working... please help to me resolve this issue. – GopalaKrishnan subramanian Commented Aug 6, 2015 at 12:43
  • i want to use this dynamic loading in my localization widgets for example datepicker like that .. please help me to achieve this. – GopalaKrishnan subramanian Commented Aug 6, 2015 at 12:44
 |  Show 1 more ment

1 Answer 1

Reset to default 3

Fast and remended way to get started:

  • Application example using npm and webpack, or
  • By checking out the other examples

Now, directly to your questions:

  1. How to create simple sample with Globalize 1.0 support.

Assuming you want to play with Globalize locally, I remend 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'

Did I answer to your 1st question here? Just let me know if you meant something else.

  1. How to get the default currency and percentage symbol using Globalize 1.0 support and how to change the symbol dynamically

If you don't know the currency, how do you know if the monetary value is correct and it corresponds to what's being formatted/displayed?

Specifications (UTS#35) explicitly advises against having a currency value per country. "Note: Currency values should never be interchanged without a known currency code. You never want the number 3.5 interpreted as $3.50 by one user and €3.50 by another. Locale data contains localization information for currencies, not a currency value for a country. A currency amount logically consists of a numeric value, plus an acpanying currency code (or equivalent). The currency code may be implicit in a protocol, such as where USD is implicit. But if the raw numeric value is transmitted without any context, then it has no definitive interpretation."

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

Note though, applications can use CLDR to deduce the currency used in a country in a certain period of time and then feed it in for currencyFormatter. See How to access culture data in globalize.js V1.0.0 for how to access CLDR data.

  1. How to get the Positive / Negative pattern for Currency/Percentage value of the specified culture and how to change the pattern dynamically

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

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 Globalize will handle the appropriate locale defaults for you, for example in Arabic you have:

Globalize("ar").formatNumber(-0.5, {style: "percent"})
// > '‏-٥٠٪'
  1. How to get the default date format of the specified culture.

Please, could you provide a use case? I don't understand what you are trying to acplish.

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

You can override the default the way you want using date format options.

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

Please, could you provide a use case? I don't understand what you are trying to acplish.

Anyway, see How to access culture data in globalize.js V1.0.0 for how to access CLDR data directly.

本文标签: javascriptHow to use Globalize 10 and get specified culture infoStack Overflow