All Projects → xpepermint → Translatedjs

xpepermint / Translatedjs

Internationalization and localization for JavaScript and Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Translatedjs

vue-translated
Internationalization (i18n) and localization (l10n) library for Vue.js v2.
Stars: ✭ 19 (+11.76%)
Mutual labels:  i18n, time, formatter, internationalization, date, format, number
Moment.php
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Stars: ✭ 900 (+5194.12%)
Mutual labels:  i18n, time, date, formatter, internationalization
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (+94.12%)
Mutual labels:  time, formatter, date, format
Gettext
PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
Stars: ✭ 578 (+3300%)
Mutual labels:  translation, i18n, internationalization
labels
Bolt Labels extension - Translatable labels for Bolt
Stars: ✭ 18 (+5.88%)
Mutual labels:  i18n, translation, internationalization
Mojito
An automation platform that enables continuous localization.
Stars: ✭ 256 (+1405.88%)
Mutual labels:  translation, i18n, internationalization
rosetta
A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.
Stars: ✭ 23 (+35.29%)
Mutual labels:  i18n, translation, internationalization
I18next
i18next: learn once - translate everywhere
Stars: ✭ 5,971 (+35023.53%)
Mutual labels:  translation, i18n, internationalization
Eo Locale
🌏Internationalize js apps 👔Elegant lightweight library based on Internationalization API
Stars: ✭ 290 (+1605.88%)
Mutual labels:  translation, i18n, internationalization
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+3558.82%)
Mutual labels:  translation, i18n, internationalization
React Localize Redux
Dead simple localization for your React components
Stars: ✭ 384 (+2158.82%)
Mutual labels:  translation, i18n, internationalization
Django Rosetta
Rosetta is a Django application that eases the translation process of your Django projects
Stars: ✭ 806 (+4641.18%)
Mutual labels:  translation, i18n, internationalization
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (+41.18%)
Mutual labels:  time, date, format
Awesome Falsehood
😱 Falsehoods Programmers Believe in
Stars: ✭ 16,614 (+97629.41%)
Mutual labels:  time, date, internationalization
plate
Internationalization library for Python
Stars: ✭ 31 (+82.35%)
Mutual labels:  i18n, translation, internationalization
Js Lingui
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript
Stars: ✭ 3,249 (+19011.76%)
Mutual labels:  translation, i18n, internationalization
Spree i18n
I18n translation files for Spree Commerce.
Stars: ✭ 338 (+1888.24%)
Mutual labels:  translation, i18n, internationalization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+2294.12%)
Mutual labels:  translation, i18n, internationalization
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+4464.71%)
Mutual labels:  translation, i18n, internationalization
pydantic-i18n
pydantic-i18n is an extension to support an i18n for the pydantic error messages.
Stars: ✭ 32 (+88.24%)
Mutual labels:  i18n, translation, internationalization

Build Status NPM Version Dependency Status

translated.js

Internationalization (i18n) and localization (l10n) library.

This library uses ECMAScript Internationalization API and industry standards ICU Message Format and Unicode CLDR locale data. It is build on top of intl-messageformat and intl-relativeformat packages from Yahoo Inc..

This is a light weight open source package for use on server or in browser (using module bundler). The source code is available on GitHub where you can also find our issue tracker.

Related Projects

  • vue-translated: Internationalization (i18n) and localization (l10n) library for Vue.js v2.

Installation

Run the command below to install the package.

$ npm install --save translated

Usage Example

import {I18n} from 'translated';

let i18n = new I18n({
  locale: 'en-US',
  messages: {
    hello: 'Hello, {name}!'
  },
  formats : {
    number: {}, // custom number formats for Intl.NumberFormat
    date: {}, // custom date formats for Intl.DateTimeFormat
    time: {} // custom time formats for Intl.DateTimeFormat
  }
});

i18n.formatMessage('hello', {name: 'John'}); // -> Hello, John!
i18n.formatNumber(1231, {format: 'decimal'}); // -> 1,231.00
i18n.formatNumber(0.81, {format: 'percent'}); // -> 80 %
i18n.formatNumber(1234, {format: 'currency'}); // -> 1,234.00 USD
i18n.formatDate(new Date(), {format: 'short'}); // -> 8. 2. 11
i18n.formatRelativeTime(new Date()); // -> 1 month ago

API

I18n({locale, messages, formats})

Core class for internationalization and localization.

Name Type Required Default Description
locale String No en-US Language culture name.
messages Object No {} Object with translations.
formats Object No {} Object with custom formats.
import {I18n} from 'translated';

let i18n = new I18n({
  locale: 'en-US',
  messages: {
    hello: 'Hello, {name}!'
  },
  formats : {
    number: {}, // custom number formats for Intl.NumberFormat
    date: {}, // custom date formats for Intl.DateTimeFormat
    time: {} // custom time formats for Intl.DateTimeFormat
  }
});

I18n.prototype.formatDate(value, options)

Converts a value into formatted date string.

Name Type Required Default Description
value Date, Integer Yes - Date object.
options Object No - Options which are passed directly into the Intl.DateTimeFormat constructor.
i18n.formatDate(Date.now(), {month: 'numeric', year: 'numeric'}); // -> 2/1974

Note that a format option is also supported and can be set to short, medium, long or full.

i18n.formatDate(Date.now(), {format: 'short'}); // -> 12/16/16

I18n.prototype.formatMessage(key, vars)

Compiles ICU message into string.

Name Type Required Default Description
key String Yes - ICU message (supports number, date, plural, and select).
vars Object No - Data object.

You can use a plural argument to select sub-messages based on a numeric value, together with the plural rules for the specified language.

i18n.formatMessage(`
  You have {num, plural,
  =0 {no photos.}
  =1 {one photo.}
  other {# photos.}
}`, {num: 3}); // -> You have 3 photos.

You can use a select argument to select sub-messages via a fixed set of keywords.

i18n.formatMessage(`
  It's {gender, select,
  male {him.}
  female {her.}
  other {something.}
}`, {gender: 'female'}); // -> It's her.

You can use a date or a time argument to convert a date variable into a date/time string. The available built-in date formats are short, medium, long and full.

i18n.formatMessage(`{val, date, short}`, {val: new Date()}); // -> 12/16/16
i18n.formatMessage(`{val, time, short}`, {val: new Date()}); // -> 4:11 PM

You can use a number argument to format a number. The available built-in number formats are integer, decimal, currency and percent.

i18n.formatMessage(`{val, number, integer}`, {val: 1234.56}); // -> 1,234

I18n.prototype.formatNumber(value, options)

Converts a value into formatted string.

Name Type Required Default Description
value Number Yes - Integer or decimal number.
options Object No - Options which are passed directly into the Intl.NumberFormat constructor.
i18n.formatNumber(1234.56, {maximumFractionDigits: 0}); // -> 1,234

Note that a format option is also supported and can be set to integer, decimal, currency and percent.

i18n.formatNumber(0.1891, {format: 'percent'}); // -> 19%

I18n.prototype.formatRelativeTime(value, options)

Converts a value into relative time (e.g. 3 days ago).

Name Type Required Default Description
value Date, Integer Yes - Date object.
options Object No - Options for customizing the output (units and style).
i18n.formatRelativeTime(Date.now()); // -> yesterday

By default, the relative time is computed to the best fit unit, but you can explicitly call it to force units to be displayed in second, minute, hour, day, month or year.

i18n.formatRelativeTime(Date.now(), {units: 'day'}); // -> 2 days ago

By default, the relative time is computed as best fit, which means that instead of 1 day ago, it will display yesterday, or in 1 year will be next year, etc. But you can force to always use the numeric alternative:

i18n.formatRelativeTime(Date.now(), {style: 'numeric'}); // -> 2 days ago

I18n.prototype.formatTime(value, options)

Converts a value into formatted time string.

Name Type Required Default Description
value Date, Integer Yes - Date object.
options Object No - Options which are passed directly into the Intl.DateTimeFormat constructor.
i18n.formatTime(Date.now(), {hour: 'numeric'}); // -> 4 PM

Note that a format option is also supported and can be set to short, medium, long or full.

i18n.formatTime(Date.now(), {format: 'short'}); // -> 4:11 PM

Support

Browsers

If you need to support old browsers with no support for Intl then you need to include a polyfill. The easiest way is to use FT Polyfill Service.

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>

Node.js

Node.js has the Intl APIs built-in, but only includes the English locale data by default. To support other languages download the latest ICU data file and then run our scripts with the --icu-data-dir option.

The easiest way to get ICU data is by installing the icu4c-data package (v0.58.2 or higher).

$ npm install save icu4c-data

Now you can run your scripts like this (Node v7+):

$ node --icu-data-dir=node_modules/icu4c-data index.js

License (MIT)

Copyright (c) 2016 Kristijan Sedlak <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].