All Projects → DoneDeal0 → Talkr

DoneDeal0 / Talkr

Talkr is a super small i18n provider for React applications. It supports Typescript, has 0 dependencies, and is very easy to use.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Talkr

Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (-21.71%)
Mutual labels:  translation, i18n, translations
Mojito
An automation platform that enables continuous localization.
Stars: ✭ 256 (+98.45%)
Mutual labels:  translation, i18n, translations
deepl-api-connector
Connector library for deepl.com rest translation api
Stars: ✭ 12 (-90.7%)
Mutual labels:  i18n, translations, translation
Developing Ios 11 Apps With Swift
Stanford 公开课,Developing iOS 11 Apps with Swift 字幕翻译
Stars: ✭ 1,237 (+858.91%)
Mutual labels:  translation, translations
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (-3.1%)
Mutual labels:  translation, i18n
Translala
Translation Toolbox for your Laravel/Symfony project (translate, stats, commons and dead translations reports, coverage, CI process)
Stars: ✭ 70 (-45.74%)
Mutual labels:  i18n, translations
Atom I18n
:atom: One Atom i18n Package for Any Locale 🌏 🌎 🌍
Stars: ✭ 56 (-56.59%)
Mutual labels:  translation, i18n
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (-12.4%)
Mutual labels:  translation, i18n
Cyrillic To Translit Js
Ultra-lightweight JavaScript library for converting Cyrillic symbols to Translit and vice versa
Stars: ✭ 91 (-29.46%)
Mutual labels:  translation, translations
Go I18n
Translate your Go program into multiple languages.
Stars: ✭ 1,834 (+1321.71%)
Mutual labels:  translation, i18n
React I18nify
Simple i18n translation and localization components and helpers for React.
Stars: ✭ 123 (-4.65%)
Mutual labels:  translation, i18n
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (-15.5%)
Mutual labels:  translation, i18n
Elm I18n
Localization for Elm apps as a pre-build phase with import and export between elm code and CSV/PO
Stars: ✭ 68 (-47.29%)
Mutual labels:  translation, i18n
Gettext Go
🆎 GNU gettext for Go (Imported By Kubernetes)
Stars: ✭ 66 (-48.84%)
Mutual labels:  translation, i18n
Transloco
🚀 😍 The internationalization (i18n) library for Angular
Stars: ✭ 1,185 (+818.6%)
Mutual labels:  translation, i18n
React Intl Hooks
React hooks for internationalization without the hassle ⚛️🌍
Stars: ✭ 64 (-50.39%)
Mutual labels:  translation, i18n
Pootle
Online translation tool
Stars: ✭ 1,346 (+943.41%)
Mutual labels:  translation, i18n
I18n Ally
🌍 All in one i18n extension for VS Code
Stars: ✭ 1,931 (+1396.9%)
Mutual labels:  translation, i18n
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+649.61%)
Mutual labels:  translation, i18n
Laravel Translatable
It's a Laravel database translations manager
Stars: ✭ 47 (-63.57%)
Mutual labels:  translation, translations
talkr logo

TALKR - DOCUMENTATION

WHAT IS IT?

Talkr is a super small i18n provider for React applications. It supports Typescript, has 0 dependencies, and is very easy to use.

features:

  • auto-detect browser language
  • auto-detect plural rules based on any language
  • dynamic translations with multiple keys
  • access deeply nested keys in json translations files

NICE! BUT HOW DOES IT WORK?

JSON

  • Create your JSON translation files.
  • Surround dynamic values by double underscores: __dynamicValue__.
  • To allow automatic plural detection, you will need to pass a count parameter to Talkr's translation function. Talkr will then chose the right word or sentence between zero, one, two, few and many.

🤓: Some languages have more complex plural rules, that may require these five options to offer a perfect user experience. For instance, Arabic handle zero, one, two, numbers between 3 and 10 and numbers over 10 as separate entities. If a language doesn't need all these subtleties - like english - you can only write zero, one and many in the JSON file.

{
  "hello": "hello",
  "feedback": {
    "error": "The connection failed",
    "success": "The connection succedeed"
  },
  "user": {
    "describe": {
      "simple": "You are __name__",
      "complex": "You are __name__ and you like __hobby__"
    }
  },
  "message-count": {
    "zero": "you don't have new messages",
    "one": "you have 1 message",
    "many": "you have __count__ messages"
  }
}

PROVIDER

  • In your index file, import your JSON translations
  • Wrap your App with Talkr Provider
  • Pass it your available languages and your defaultLanguage.
  • You also have the option to let Talkr detect browser's language with the prop detectBrowserLanguage (see #Props).
import * as React from "react";
import ReactDOM from "react-dom";
import { Talkr } from "talkr";
import App from "./app";
import en from "./i18n/en.json";
import fr from "./i18n/fr.json";

ReactDOM.render(
  <Talkr languages={{ en, fr }} defaultLanguage="en">
    <App />
  </Talkr>,
  document.getElementById("root")
);

SIMPLE USAGE

  • In any component, import Talker's translation function T.
  • Fetch the desired sentence as if you were directly accessing an object, by adding . between each key. Based on the JSON example above, we could print the sentence The connection succedeed by simply writing T("feedback.success")
import React from "react";
import { T } from "talkr";

export default function MyComponent() {
  return (
    <>
      <h1>{T("hello")}</h1>
      <div>{T("feedback.success")}</div>
    </>
  );
}

DYNAMIC VALUES

  • To handle dynamic translations, just add an object with all necessary dynamic values
  • To make it work, you need to surround the dynamic values by double underscores in your JSON files (__dynamicValue__)
import React from "react";
import { T } from "talkr";

export default function MyComponent() {
  return (
    <>
      <h1>{T("user.describe.complex", { name: "joe", hobby: "coding" })}</h1>
    </>
  );
}

PLURAL

  • To handle plural, just add a count property to the object
  • To make it work, you need to provide both zero, one and many values to your JSON files.
import React, { useState } from "react";
import { T } from "talkr";

export default function MyComponent() {
  const [count, setCount] = useState(0);
  return (
    <>
      <h1>{T("message-count", { count })}</h1>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </>
  );
}

LOCALE

  • Access and update the locale by using the hook useLocale()
  • If the provided locale doesn't match any JSON translation files, Talkr will use the defaultLanguage sent to the provider.
import React, { useState } from "react";
import { T, useLocale } from "talkr";

export default function MyComponent() {
  const { setLocale, locale } = useLocale();
  return (
    <>
      <h1>{T("hello")}</h1>
      <p>{locale}</p>
      <button onClick={() => setLocale("fr")}>speak french</button>
    </>
  );
}

PROPS

Provider

You can pass these props to Talkr's provider | |Type |Role | |----------------|-------------------------------|-----------------------------| |languages |object |object containing all your json files. Typical format: {en: {...}, fr: {...}} | |defaultLanguage |string |default language of your app (a similar key must be included in the language prop) | |detectBrowserLanguage |boolean|if true, Talkr will automatically use browser language and override the defaultLanguage. If the browser language is not included in your available translations, it will switch back to defaultLanguage.|

🤓: The auto-detect language feature will always return a simple key such as 'fr' instead of 'fr_FR'. Keep things simple and always declare your languages with 2 letters.

useLocale

You can access these props from Talkr's hook useLocale() | |Type |Role | |----------------|-------------------------------|-----------------------------| |locale |string |returns the current locale | |setLocale |(locale: string) => void |function to update the locale
|defaultLanguage |string|returns the App's default language| |languages |object|returns all your JSON translations|

SUPPORT

Listen to Noir Empire (dark rock & trip-hop):

https://www.facebook.com/Noir-Empire-101478985118273

https://www.instagram.com/noir_empire/

https://soundcloud.com/noir-empire

https://www.youtube.com/channel/UCwUU5Qa-AWKiNTGmyfh1LdQ

"The Way She Rocks" - Out November 13th, 2020.

CREDITS

DoneDeal0

Mouth logo made by emilegraphics from the Noun Project

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