Converting dates, numbers, and currency
Localizing Dates and Times
Dates and times are commonly found on many websites and mobile apps, and the localization of dates varies from language to language. To solve this problem, you can use several external libraries to convert dates to formats used in other languages.
External Libraries for Localizing Dates/Times
Here are a few examples of external libraries you can use:
- Luxon
- date-fns
- Globalize.js
- Moment.js (NOTE: Moment.js is a legacy project and not recommended for use in new projects.)
Tell Localize about your converted dates/times
After you've implemented the localization of dates/times in your website or app, the next step is to tell Localize to ignore those dates/times that it finds in your content.
Here are a few methods that you can use, depending on your situation:
- Define variables in your phrases
- Add
<var>
tags to your HTML - Use the Block CSS Classes and IDs feature
- Add an
ignore
attribute
Examples:
<p>The ski trip is schedled from <var start>3/8/2023</var> to <var end>3/14/2023</var>.</p>
<p>The ski trip is schedled from <span ignore>3/8/2023</span> to <span ignore>3/14/2023</span>.</p>
Localizing Ordinal Numbers
Ordinal numbers are sometimes found in many websites and mobile apps, and the localization of them varies from language to language. To solve this problem, there are a number of external libraries that you can use to convert ordinal number formats used in other languages.
External libraries for localizing ordinal numbers
Here are a few examples of external libraries you can use:
- Moment.js
- Useful for ordinal numbers inside of dates.
- Numeral.js
- Angular Localization and Internationalization
- You can use this library if you are using Angular to create your site/app.
- Use the built in i18n features of JavaScript: the Intl object
- Check out this article to get started: How to get started with internationalization in JavaScript
- Globalize.js
Tell Localize about your converted ordinal numbers
After you've implemented the localization of ordinal numbers in your website or app, the next step is to tell Localize whether to ignore those ordinal numbers that it finds in your content (if you've already provided the complete website translations).
Here are a few methods that you can use, depending on your situation:
- Define variables in your phrases
- Add
<var>
tags to your HTML - Use the Block CSS Classes and IDs feature
- Add an
ignore
attribute
Examples:
<p>That's the <var num-visits>2nd</var> time she's visited Norway.</p>
<p>That's the <span ignore>2nd</span> time she's visited Norway.</p>
Use the Localize.number() Method
You may be able to use the number() method available in our Frontend API. Read more here.
Localizing Currency
Phrases that contain currency in them are found on many websites and mobile apps, and localization methods vary from language to language. To solve this problem, there are a number of external libraries that you can use to convert currency formats used in other languages.
External libraries for localizing currency
Here are a few examples of external libraries you can use:
- Numeral.js
- Use the built in i18n features of JavaScript: the Intl object
- Check out this article to get started: How to get started with internationalization in JavaScript
- Globalize.js
Tell Localize about your converted currency numbers
After you've implemented the localization of currency in your website or app, the next step is to tell Localize whether to ignore those numbers that it finds in your content (if you've already provided the complete translations).
Here are a few methods that you can use, depending on your situation:
- Define variables in your phrases
- Add
<var>
tags to your HTML - Use the Block CSS Classes and IDs feature
- Add an
ignore
attribute
Examples:
<p>That fishing rod costs <var price>$95.99</var>.</p>
<p>That fishing rod costs <span ignore>$95.99</span>.</p>
Use the Localize.currency() Method
You may be able to use the currency() method available in our Frontend API. Read more here.
Updated almost 2 years ago