All Projects → jeandeaual → go-locale

jeandeaual / go-locale

Licence: MIT license
GoLang library used to retrieve the current locale(s) of the operating system.

Programming Languages

go
31211 projects - #10 most used programming language
c
50402 projects - #5 most used programming language
Dockerfile
14818 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to go-locale

rosetta
A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.
Stars: ✭ 23 (+43.75%)
Mutual labels:  i18n, localization, l10n, locale
awesome-translations
😎 Awesome lists about Internationalization & localization stuff. l10n, g11n, m17n, i18n. Translations! 🌎🌍
Stars: ✭ 54 (+237.5%)
Mutual labels:  i18n, localization, l10n, locale
cldr-engine
Internationalization and localization in Typescript with Unicode CLDR, batteries included
Stars: ✭ 34 (+112.5%)
Mutual labels:  i18n, localization, locale
React Native Globalize
Internationalization (i18n) for React Native
Stars: ✭ 246 (+1437.5%)
Mutual labels:  i18n, localization, l10n
stone.js
gettext-like client-side Javascript Internationalization Library
Stars: ✭ 20 (+25%)
Mutual labels:  i18n, localization, l10n
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+993.75%)
Mutual labels:  i18n, localization, l10n
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+16893.75%)
Mutual labels:  i18n, localization, l10n
lisan
🌈i18n, Reimagined! 🚀A blazing fast and super small i18n library for Javascript
Stars: ✭ 85 (+431.25%)
Mutual labels:  i18n, localization, l10n
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (+681.25%)
Mutual labels:  i18n, localization, l10n
msgtools
Tools for Developing Diagnostic Messages
Stars: ✭ 18 (+12.5%)
Mutual labels:  i18n, localization, l10n
awesome-i18n
🌍 A curated list of i18n resources for all kind of languages and frameworks
Stars: ✭ 205 (+1181.25%)
Mutual labels:  i18n, localization, l10n
figma-static-localizer
A Figma plugin for static localization
Stars: ✭ 30 (+87.5%)
Mutual labels:  i18n, localization, l10n
Es2015 I18n Tag
ES2015 template literal tag for i18n and l10n (translation and internationalization)
Stars: ✭ 171 (+968.75%)
Mutual labels:  i18n, localization, l10n
Serge
Continuous localization platform
Stars: ✭ 212 (+1225%)
Mutual labels:  i18n, localization, l10n
Punic
PHP translation and localization made easy!
Stars: ✭ 133 (+731.25%)
Mutual labels:  i18n, localization, l10n
locale-switcher
Browser Extension to quickly change your browser locale.
Stars: ✭ 75 (+368.75%)
Mutual labels:  localization, l10n, locale
android-studio-plugin
Integrate your Android project with Crowdin
Stars: ✭ 52 (+225%)
Mutual labels:  i18n, 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 (+406.25%)
Mutual labels:  i18n, localization, l10n
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (+581.25%)
Mutual labels:  i18n, localization, l10n
vue-i18n
A small package for implementing translations in Vue.js
Stars: ✭ 40 (+150%)
Mutual labels:  i18n, l10n, locale

go-locale

PkgGoDev Go Report Card Coverage Status test

Go library used to retrieve the current locale(s) of the operating system.

OS Support

Usage

GetLocales

GetLocales returns the user's preferred locales, by order of preference, as a slice of IETF BCP 47 language tag (e.g. []string{"en-US", "fr-FR", "ja-JP"}).

This works if the user set multiple languages on macOS and other Unix systems. Otherwise, it returns a slice with a single locale.

userLocales, err := locale.GetLocales()
if err == nil {
	fmt.Println("Locales:", userLocales)
}

This can be used with golang.org/x/text or go-i18n to set the localizer's language preferences:

import (
	"github.com/jeandeaual/go-locale"
	"golang.org/x/text/message"
)

func main() {
	userLocales, _ := locale.GetLocales()
	p := message.NewPrinter(message.MatchLanguage(userLocales...))
	...
}
import (
	"github.com/jeandeaual/go-locale"
	"github.com/nicksnyder/go-i18n/v2/i18n"
	"golang.org/x/text/language"
)

func main() {
	userLocales, _ := locale.GetLocales()
	bundle := i18n.NewBundle(language.English)
	localizer := i18n.NewLocalizer(bundle, userLocales...)
	...
}

For a complete example, see here.

GetLocale

GetLocale returns the current locale as defined in IETF BCP 47 (e.g. "en-US").

userLocale, err := locale.GetLocale()
if err == nil {
	fmt.Println("Locale:", userLocale)
}

GetLanguage

GetLanguage returns the current language as an ISO 639 language code (e.g. "en").

userLanguage, err := locale.GetLanguage()
if err == nil {
	fmt.Println("Language:", userLocale)
}

GetRegion

GetRegion returns the current language as an ISO 3166 country code (e.g. "US").

userRegion, err := locale.GetRegion()
if err == nil {
	fmt.Println("Region:", userRegion)
}

Aknowledgements

Inspired by jibber_jabber.

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