All Projects → pote → Int

pote / Int

Licence: mit
Tiny in-browser internationalization.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Int

Eo Locale
🌏Internationalize js apps 👔Elegant lightweight library based on Internationalization API
Stars: ✭ 290 (+1712.5%)
Mutual labels:  i18n, tiny, internationalization
Fbt
A JavaScript Internationalization Framework
Stars: ✭ 3,668 (+22825%)
Mutual labels:  i18n, internationalization
Vue I18n
🌐 Internationalization plugin for Vue.js
Stars: ✭ 6,502 (+40537.5%)
Mutual labels:  i18n, internationalization
Babel Plugin React Intl
Extracts string messages from React components that use React Intl.
Stars: ✭ 430 (+2587.5%)
Mutual labels:  i18n, internationalization
React I18next
Internationalization for react done right. Using the i18next i18n ecosystem.
Stars: ✭ 6,942 (+43287.5%)
Mutual labels:  i18n, internationalization
Django Rosetta
Rosetta is a Django application that eases the translation process of your Django projects
Stars: ✭ 806 (+4937.5%)
Mutual labels:  i18n, internationalization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+2443.75%)
Mutual labels:  i18n, internationalization
Js Lingui
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript
Stars: ✭ 3,249 (+20206.25%)
Mutual labels:  i18n, internationalization
Laravel Js Localization
🌐 Convert your Laravel messages and consume them in the front-end!
Stars: ✭ 451 (+2718.75%)
Mutual labels:  i18n, internationalization
Timeago.js
🕗 ⌛ timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.
Stars: ✭ 4,670 (+29087.5%)
Mutual labels:  i18n, tiny
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+4750%)
Mutual labels:  i18n, internationalization
Spree i18n
I18n translation files for Spree Commerce.
Stars: ✭ 338 (+2012.5%)
Mutual labels:  i18n, internationalization
Gotext
Go (Golang) GNU gettext utilities package
Stars: ✭ 292 (+1725%)
Mutual labels:  i18n, internationalization
I18next
i18next: learn once - translate everywhere
Stars: ✭ 5,971 (+37218.75%)
Mutual labels:  i18n, internationalization
I18n Editor
GUI for editing your i18n translation files
Stars: ✭ 290 (+1712.5%)
Mutual labels:  i18n, internationalization
React Localize Redux
Dead simple localization for your React components
Stars: ✭ 384 (+2300%)
Mutual labels:  i18n, internationalization
I18n4go
i18n tooling for Golang
Stars: ✭ 264 (+1550%)
Mutual labels:  i18n, internationalization
Gettext
PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
Stars: ✭ 578 (+3512.5%)
Mutual labels:  i18n, internationalization
Svelte I18n
Internationalization library for Svelte
Stars: ✭ 433 (+2606.25%)
Mutual labels:  i18n, internationalization
Fluent Rs
Rust implementation of Project Fluent
Stars: ✭ 503 (+3043.75%)
Mutual labels:  i18n, internationalization

int - (some) internationalization.

This is a minimal in-browser internationalization solution: if you are doing a static page this might be what you need to support multiple languages, although it can easily be used in more complex setups.

Usage

Require and initialization

Since it will govern what text to display it's a good idea to require int as soon as possible, I recommend doing it in your <head> element.

<script type="text/javascript" src="js/int.js"></script>

Right after that, you'll want to initialize it:

<script>
  int = new Int({
    default_locale: 'en',
    available_locales: ['en', 'es']
  });
</script>

Markup

You'll need to use the lang attribute in all elements you want to internationalize, like so:

<p lang="en">
  A long time ago in a galaxy far, far away...
</p>

<p lang="es">
  Hace mucho tiempo en una galaxia muy, muy lejana...
</p>

In the above markup, only the element with the lang attribute matching the current int.locale will be displayed.

Switching languages

You can toggle available locales easily:

int.toggle('es');

#toggle saves the locale you're selecting to localStorage, so the appropriate language will be loaded on page reloads.

Language Picker

So you can create a language picker of your choice just as easily:

<a href="#" onclick="int.toggle('en')">English</a>
<a href="#" onclick="int.toggle('es')">Español</a>

Detect user's language

The detect option is set to false by default, but if enabled, it will attempt to toggle the user's browser navigator.language automatically on load, unless that user has explicitly toggled a preferred language before.

<script>
  int = new Int({
    default_locale: 'en',
    available_locales: ['en', 'es'],
    detect: true
  });
</script>

Strict mode vs lax matching

When using detect: true you might not want to make a difference between, say, en-US and en-UK, as that would mean writing a ton of repetitive language elements.

However, if you set the strict option to false in the constructor then Int will only pay attention to the first two characters of the user's preferred language, so any en-* in navigator.language will match your en elements.

<script>
  int = new Int({
    default_locale: 'en',
    available_locales: ['en', 'es'],
    detect: true,
    strict: false
  });
</script>

Styling, right-to-left text, etc.

Int is a very tiny solution and doesn't include custom language display styles, however, by using the standard html lang property it gives you the ability to style individual languages easily. For example: if you want Arabic to be displayed with its proper right-to-left style, simply add this to your CSS:

:lang(ar) {
  direction: rtl;
}

That's it.

Int is (for now) an immature project, it is running in production in a few sites but you must keep in mind that the main usecase is simple static sites hosted in places like github pages:

It might not be your cup-of-tea, it might not solve your use case, that's okay: Int won't attempt to solve internationalization for everyone, instead it will attempt to solve it elegantly for some people, there are plenty of other solutions out there already :).

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].