Live Platform
  • Introduction
  • Release Notes
    • Live 3
      • 3.59.0
      • 3.58.0
      • 3.57.0
      • 3.56.0
      • 3.55.0
      • 3.54.0
      • 3.53.0
      • 3.52.0
      • 3.51.0
      • 3.50.0
      • 3.49.0
      • 3.48.0
      • 3.47.0
      • 3.46.0
      • 3.45.0
      • 3.44.0
      • 3.43.0
      • 3.42.0
      • 3.41.0
      • 3.40.0
      • 3.39.0
      • 3.38.0
      • 3.37.0
      • 3.36.0
      • 3.35.0
      • 3.34.0
      • 3.33.0
      • 3.32.0
      • 3.31.0
      • 3.30.0
      • 3.29.0
      • 3.28.0
      • 3.27.0
      • 3.26.0
      • 3.25.0
      • 3.24.0
      • 3.23.0
      • 3.22.0
      • 3.21.0
      • 3.20.0
      • 3.19.0
      • 3.18.0
      • 3.17.0
      • 3.16.0
      • 3.15.0
      • 3.14.0
      • 3.13.0
      • 3.12.0
      • 3.11.0
      • 3.10.0
      • 3.9.0
      • 3.8.0
      • 3.7.0
      • 3.6.0
      • 3.5.0
      • 3.4.0
      • 3.3.0
      • 3.2.0
      • 3.1.0
      • 3.0.0
    • Live 2
  • Articles
    • Creating an aggregation
    • Creating a pipe
  • Theoretical Background
    • Fundamentals
    • Key Advantages
  • Platform Architecture
    • Introduction
    • Queries
    • Glossary
  • Featured plugins
    • Annotations
    • Groovy support
    • Messenger
    • Microsoft Teams
    • MongoDB
    • MongoDB Timeseries
    • MongoDB Kit
    • Purge plugin
    • SQL
    • TCP Input
    • TimescaleDB
  • Data visualization
    • Pipes widgets
      • Temporal
      • Cartesian
      • Multi-value snapshot
      • Single-value snapshot
      • Tables
      • Heatmap
      • JSX Widgets
      • Lollipop
      • Histogram
      • State Timeline
      • Boxplot
    • Pipes modifiers on Pipes charts
  • Alerts and notifications
    • Pipes modifiers on rules
  • Pipes Queries
    • Introduction
    • Dynamic filters
    • Meta parameters
    • Reducer
      • Uniform compress
      • PIP
    • Storage Hints
    • Execution Context
    • Event flow modifiers
  • Developers
    • Plugins
    • Packages
    • Backend API
      • Lookup Tables
      • Extensions
      • Settings
      • Storage Providers
      • Web Services
      • Web Setup
      • Entity Audit
    • Web application
      • Services
        • Point service
        • Menu service
      • Browser Compatibility
      • Runtime modules
        • Core Javascript modules
        • Library modules
        • Adding modules to runtime
      • Localization (i18n)
      • Date formatting
      • Dashboard and Widgets
        • Widget API
        • Custom widget editors
        • Live Event Types
        • Live Widget Configuration
        • Live Widget Packaging
        • Widget Request Interceptors
      • React Contexts
        • Dashboard
        • Dashboard widget
      • Registering Home Page options
    • Python application
    • Subscribing to Live Events
  • Administration
    • Configuration
      • Home Page Customization
      • live.properties
    • Infrastructure Monitoring
    • Storage Monitoring
    • Queries Monitoring
    • Logs Monitoring
    • Data Purging
  • Features
    • Access Permission
    • Datasources
    • Export Dashboard
    • Partial Indexes
    • WebApp Metrics
    • Entity Audit
Powered by GitBook
On this page
  • Import
  • Registering translations
  • Locale files
  • Parameters, pluralization, functions
  • API
  • Usage

Was this helpful?

  1. Developers
  2. Web application

Localization (i18n)

The locale setting is located in Web Settings on the admin section. Currently English and Portuguese languages are supported.

Text localization can be done using the Live own i18n service.

Import

import i18n from 'live/services/i18n'

Registering translations

import locale from 'live/init/global-locale'
import i18n from 'live/services/i18n'
import pt_br from './i18n/pt_br'
import en_us from './i18n/en_us'

var localeFiles = {
    pt_br: pt_br,
    en_us: en_us
}

// register current locale file
i18n.add(localeFiles[locale])

Locale files

i18n/pt_br.js
export default {
    values: {
       book: "livro"
    }
}

Parameters, pluralization, functions

Translations can received simple parameters that will be expanded for each locale string

i18n/pt_br.js
export default {
    values: {
        'Hi %{user} welcome to our book store': 
            'Olá %{user} bem vindo à nossa loja de livros'
    }
}

The parameters can also be used for a very simple pluralization logic

i18n/en_us.js
export default {
    values: {
        '%{count} books were added to cart': [
            [1, 1, 'a book was added to cart'],
            [2, 99, '%{count} books were added to cart'],
            [100, null, '99+ books were added to cart']
        ]
    }
}

Translation values can be functions that will be rendered as React components

i18n/en_us.js
export default {
    values: {
       'book-count': function BookCount ({ count }) {
           if (count === 0) return <span style={{color: 'red'}}>There are no books</span>
           if (count === 1) return <span style={{color: 'green'}}>There is one book</span>

           return <span> There are {count} books </span>
       }
    }
}

API

type i18nString = (translation: string) => string

// passing props to function values
type i18nComponent = 
    (translation: string, props: Record<string, any>) => React.ReactNode

type i18n = i18nString | i18nComponent

Usage

function SimpleExample ()  { return <span>{i18n('book')}</span> }

function Greetings() { 
  return 
    <span>
      {i18n('Hi %{user} welcome to our book store', { user: 'John Doe' })}
    </span> 
}

function CartInfo() {
  return <span>{i18n('%{count} books were added to cart', { count: 123 })}</span>
}

function BookCounter () {
  const [ count, setCount ] = React.useState(0)

  return <div onClick={() => setCount(s => s + 1)} >{i18n('book-count', { count })}</div>
}
PreviousAdding modules to runtimeNextDate formatting

Last updated 2 years ago

Was this helpful?