All Projects → unknwon → i18n

unknwon / i18n

Licence: Apache-2.0 License
Package i18n is for app Internationalization and Localization.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to i18n

stone.js
gettext-like client-side Javascript Internationalization Library
Stars: ✭ 20 (-74.68%)
Mutual labels:  i18n, internationalization, localization, l10n
rosetta
A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.
Stars: ✭ 23 (-70.89%)
Mutual labels:  i18n, internationalization, localization, l10n
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+121.52%)
Mutual labels:  i18n, internationalization, localization, l10n
inlang
Open Source Localization Solution for Software.
Stars: ✭ 160 (+102.53%)
Mutual labels:  i18n, internationalization, localization, l10n
msgtools
Tools for Developing Diagnostic Messages
Stars: ✭ 18 (-77.22%)
Mutual labels:  i18n, internationalization, localization, l10n
android-studio-plugin
Integrate your Android project with Crowdin
Stars: ✭ 52 (-34.18%)
Mutual labels:  i18n, internationalization, localization, l10n
lisan
🌈i18n, Reimagined! 🚀A blazing fast and super small i18n library for Javascript
Stars: ✭ 85 (+7.59%)
Mutual labels:  i18n, internationalization, localization, l10n
Keys Translations Manager
KTM, a locale management web app built on MERN stack, lets you manage and control locales in one place. It's particularly useful for someone who needs to manage multiple internationalization/localization projects.
Stars: ✭ 81 (+2.53%)
Mutual labels:  i18n, internationalization, localization, l10n
awesome-i18n
🌍 A curated list of i18n resources for all kind of languages and frameworks
Stars: ✭ 205 (+159.49%)
Mutual labels:  i18n, internationalization, localization, l10n
React Native Globalize
Internationalization (i18n) for React Native
Stars: ✭ 246 (+211.39%)
Mutual labels:  i18n, internationalization, localization, l10n
I18N
I18N Library for .NET, and Delphi
Stars: ✭ 48 (-39.24%)
Mutual labels:  i18n, internationalization, localization, l10n
i18n
internationalize projects to Arabic
Stars: ✭ 67 (-15.19%)
Mutual labels:  i18n, internationalization, localization, l10n
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (+58.23%)
Mutual labels:  i18n, internationalization, localization, l10n
Angular-Gulp-Boilerplate
Clean but full-featured AngularJS boilerplate using Gulp workflow and best practices
Stars: ✭ 30 (-62.03%)
Mutual labels:  i18n, internationalization, localization, l10n
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (+37.97%)
Mutual labels:  i18n, internationalization, localization, l10n
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+3341.77%)
Mutual labels:  i18n, internationalization, localization, l10n
Redux React I18n
An i18n solution for React/Redux and React Native projects
Stars: ✭ 64 (-18.99%)
Mutual labels:  i18n, internationalization, localization, l10n
Locale2
💪 Try as hard as possible to detect the client's language tag ("locale") in node or the browser. Browserify and Webpack friendly!
Stars: ✭ 65 (-17.72%)
Mutual labels:  i18n, internationalization, localization, l10n
Serge
Continuous localization platform
Stars: ✭ 212 (+168.35%)
Mutual labels:  i18n, internationalization, localization, l10n
figma-static-localizer
A Figma plugin for static localization
Stars: ✭ 30 (-62.03%)
Mutual labels:  i18n, internationalization, localization, l10n

i18n

GitHub Workflow Status codecov GoDoc Sourcegraph

Package i18n is for app Internationalization and Localization.

Introduction

This package provides multiple-language options to improve user experience. Sites like Go Walker and gogs.io are using this module to implement Chinese and English user interfaces.

You can use following command to install this module:

go get github.com/unknwon/i18n

Usage

First of all, you have to import this package:

import "github.com/unknwon/i18n"

The format of locale files is very like INI format configuration file, which is basically key-value pairs. But this module has some improvements. Every language corresponding to a locale file, for example, suppose there are two files called locale_en-US.ini and locale_zh-CN.ini.

The name and extensions of locale files can be anything, but we strongly recommend you to follow the style of gogsweb.

Minimal example

Here are two simplest locale file examples:

File locale_en-US.ini:

hi = hello, %s
bye = goodbye

File locale_zh-CN.ini:

hi = 您好,%s
bye = 再见

Do Translation

There are two ways to do translation depends on which way is the best fit for your application or framework.

Directly use package function to translate:

i18n.Tr("en-US", "hi", "Unknwon")
i18n.Tr("en-US", "bye")

Or create a struct and embed it:

type MyController struct{
    // ...other fields
    i18n.Locale
}

//...

func ... {
    c := &MyController{
        Locale: i18n.Locale{"en-US"},
    }
    _ = c.Tr("hi", "Unknwon")
    _ = c.Tr("bye")
}

Code above will produce correspondingly:

  • English en-UShello, Unknwon, goodbye
  • Chinese zh-CN您好,Unknwon, 再见

Section

For different pages, one key may map to different values. Therefore, i18n module also uses the section feature of INI format configuration to achieve section.

For example, the key name is about, and we want to show About in the home page and About Us in about page. Then you can do following:

Content in locale file:

about = About

[about]
about = About Us

Get about in home page:

i18n.Tr("en-US", "about")

Get about in about page:

i18n.Tr("en-US", "about.about")

Ambiguity

Because dot . is sign of section in both INI parser and locale files, so when your key name contains . will cause ambiguity. At this point, you just need to add one more . in front of the key.

For example, the key name is about., then we can use:

i18n.Tr("en-US", ".about.")

to get expect result.

Helper tool

Module i18n provides a command line helper tool beei18n for simplify steps of your development. You can install it as follows:

go get github.com/unknwon/i18n/ui18n

Sync locale files

Command sync allows you use a exist local file as the template to create or sync other locale files:

ui18n sync source_file.ini other1.ini other2.ini

This command can operate 1 or more files in one command.

More information

  • The first locale you load to the module is considered as default locale.
  • When matching non-default locale and didn't find the string, i18n will have a second try on default locale.
  • If i18n still cannot find string in the default locale, raw string will be returned. For instance, when the string is hi and it does not exist in locale file, simply return hi as output.
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].