Releases: alexdrel/i18n-react
Better literal syntax
Allows matching number of backticks (with optional whitespace) to form a literal. This allows quoting of the backtick pairs: ``` `` ```
=> ``
.
Passing MDText in the React 16.3+ Context
MDText object can be passed around using new official react context API.
import { MDText } from 'i18n-react';
let MDTextContext = React.createContext();
let Texts = new MDText({...});
<MDTextContext.Provider value={Texts}>
<MDTextContext.Consumer>{ (T) =>
<T.span text="path.to.string" />
}</MDTextContext.Consumer>
</MDTextContext.Provider>
See updated examples/yaml for complete example.
Adds the ability to provide a function for notFound or translation dictionary
notFound
property can be either a string, or a function returning a string.
If it is a string, then it will be returned as is any time a key is missing.
If you provide a function, then the function will be run with the missing key
and context as arguments.
T.setTexts(translations, {
notFound: key => `**${key}**` // will render <strong>SomeKey</strong>
})
Translation dictionaries can be extended with functions (as in notFound).
T.setTexts({
a: 'A',
n: (_key, ctx) => ctx ? `Number ${ctx}` : '',
});
T.translate('a')) // 'A'
T.translate('n', { context: 9 })) // 'Number 9'
Fix for Gratuitous Literals
Fix #33 (Gratuitous literal)
Literal quotes \`\` in V1 syntax
New `` syntax `` (in V1 only) to disable MD processing.
React 16+ required
As React now allows fragments and strings in render the default behavior of <T.text>
changed not to wrap the output into <span>
when tag
property is not specified.
New MD syntax
The new MD flavor (aligned with github's Markdown) is added : V1. Opt-in for this release, will become default in the next major release.
V1 introduces strike and underline, and rehabilitates <b>
and <i>
tags.
em: "an *italic* style"
i: "an _italic_ style"
strong: "a **bold** move"
b: "a __bold__ move"
u: "an ~underlined~ word"
strike: "a ~~strike~~ out"
To opt-in for the new syntax:
let T = new MDText(texts, { MDFlavor: 1 });
// or for the singelton
T.setTexts(require('../texts/texts-en.yml'), { MDFlavor: 1, notFound: 'NA' });
MDText notFound property is deprecated - please switch to constructor or serTexts options.
Typescript 1.8 compatibilty workaround
Disabled export typing of TS 2.0 for compatibility with currently stable Typescript 1.8
React 15.2 and @typings
Unknown Prop Warning
React 15.2 is preparing to stop filtering HTML properties - the feature that i18n relied upon for preventing interpolation variables from leaking into the DOM.
Thus new syntax for passing variables is introduced:
<T.span text={{ key: "greeting", myName: "i18n-react" }}/>
/* replaces */
<T.span text="greeting" myName="i18n-react"/>
All tags passing to T.* anything beside text
, tag
and context
properties have to be updated or React 15.2 will cry annoyingly.
typescript 2.0 / ts@next typings
Updated package.json contains all the info for the new typescript to get typings automatically.
ES6 ready
- ES6 style export (use default export explicitly for commonJS/UMD)
- Stateless react components (shouldComponentUpdate optimization removed)
- Default export (T above) no longer can be used as a react component (use T.text or T.span instead)