fallenmax / a18n Goto Github PK
View Code? Open in Web Editor NEWAutomated I18n solution for JavaScript/TypeScript/React
Home Page: https://www.npmjs.com/package/a18n
License: MIT License
Automated I18n solution for JavaScript/TypeScript/React
Home Page: https://www.npmjs.com/package/a18n
License: MIT License
See if it's possible/easy to support .vue
function App() {
const [language, setLanguage] = useState('');
useEffect(() => {
const language = Cookies.get('lang') || getUrlParam('lang') || navigator.language || 'zh';
a18n.setLocale(language);
setLanguage(language);
}, []);
return (
setLocale not working like above.
From different a18n
code/instances in same page, a18n.getA18n(sameNamespace)
always yield same a18n instance (i.e. sharing locale/resource/cache)
a18n might store locale resources in global (window) underlying.
In micro-frontend or application/components architecture, we might have multiple parts of system, each of which independently depends on a18n (probably with different versions) , but would like to share same locale resources for consistency.
To simplify the process of passing locale resources to each part, a18n could provide a mechanism to explicitly share global locale resources.
Instances will not be shared across tab/worker/iframe, some user-land sharing solutions are still required in these scenarios.
Background:
To support partial wrap/extract (i.e. only operate on a subset of a codebase, like changed files) workflow.
Plan:
--no-prune
option to extract
commandAdd a18n check
command, that checks:
un-extracted
textsun-wrapped
textsThis command can be integrated into CI pipeline to check if there are texts missing translation.
Maybe we should wrap JSX Text as a whole?
(Inspired by ttag)
let desc = <strong>nice</strong>
let vdom = <div>Today is a {desc} day <div>
// should be wrapped as:
let desc = <strong>nice</strong>
let vdom = <div>{a18n.x`Today is a {desc} day`}<div> // a18n.x returns array instead of string
// and extracted to key: "Today is a %1 day"
Currently we only wrap StringLiteral and TemplateLiterals inside JSX Element children, this:
<span>aaa <strong>bbb</strong> ccc</span>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.