roddeh / i18njs Goto Github PK
View Code? Open in Web Editor NEWInternationalisation library for JS projects
License: MIT License
Internationalisation library for JS projects
License: MIT License
I'm using your lib in my work and when you have couple hunders entities then it's really starting to be painful to maintain all translations. I was thinking about starting writing tool (or e.g. VS Code plugin?) that will allow to maintain those files. What do you think?
Now that npm
is initialized I suggest to publish package:
https://docs.npmjs.com/getting-started/publishing-npm-packages
:)
Can you please provide a definitions file for typescript? http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
Here is a great repo: https://github.com/DefinitelyTyped/DefinitelyTyped
locale:
navbar: {
menu: {
listOfTutorials: 'List of tutorials',
},
},
I want to display t('navbar.menu.listOfTutorials')
but nothing happens
Hi,
I'm using your library in couple projects already. Simplicity of this library is just sweet. What I'm missing is support for num === null
. Scenario? Let's say that I have dynamic translation of sentence that is working on numbers. So my translation is looking like:
...
"DEVICES": [
[null, null, "Some error - please check your syntax"],
[0, 0, "No devices available"],
[1, 1, "%n device available"],
[2, null, "%n devices available"]
],
...
With above triplets I can condition and support for example errors if I like. It's just example. The most important stuff is that you don't need to do any other conditions in code - triplet [null, null, "Text"]
could easly handle it. I have even implemented it already in my copy of your library. If you are interested then I can fork repo and do a PR. Let me know what do you think.
Cheers,
Marek
It would be nice to have an official release of the current repo state as a new version to the NPM registry.
Is it planned to include ability to specify pluralization rules for a language such as Russian, where there are much more word forms depending on the count of objects, such as:
{
values:{
"%d results": {
zero: "нет результатов",
one: "1 результат",
few: "%n результата",
many: "%n результатов",
other: "%n результаты"
}
}
}
// English
{
values:{
"%d results": {
zero: "No results",
one: "1 result",
other: "%n results"
}
}
}
Russian pluralization rules:
function (value) {
if (!value) {
return "zero";
}
if (value % 10 == 1 && value % 100 != 11) {
return "one";
}
if ([2, 3, 4].indexOf(value % 10) >= 0 && [12, 13, 14].indexOf(value % 100) < 0) {
return "few";
}
if (value % 10 == 0 || [5, 6, 7, 8, 9].indexOf(value % 10) >= 0 || [11, 12, 13, 14].indexOf(value % 100) >= 0) {
return "many";
}
return "other";
}
Pluralization rules can be found at http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
I've read the documentation on the main page and found this library vary intuitive and simple to use. Unlike i18next it is not huge but covering most the needs you have developing localized solution.
Unfortunately, I don't have time to be a maintainer of the library this. Like to make ad upgrade to esmodules support, modern frameworks integration, tests, ect. But I like the work has done. It is really, one of the best solution I found in my todays research.
It would be nice to set up some rules and start using linter.
How about integration with Travis? Whenever someone will create PR, Travis would run tests - so you will know if it's safe to merge it or not? :)
It would be nice to start using Mocha + Chai. If you are open to this then I can help with moving.
Hi,
I really like the idea with a lightweight i18n. But trying to integrate it to a project using eslint there are lot of syntax and other errors (sample below but there are more than 140 reported). The --fix option does fix a lot but still leaves at least 18 errors. Fixing this is beyond my capabilities. And I realize this falls into the category if it ain't broken don't fix it. But maybe there is a chance to update this to a tighter syntax could have some benefits. Thank you for an awesome project!
[admin@penguin js]$ npx eslint i18n.js
2:10 error Missing space before function parentheses space-before-function-paren
3:5 error Expected newline after "use strict" directive lines-around-directive
3:17 error Expected this semicolon to be at the beginning of the next line semi-style
4:9 error Expected a function declaration func-style
4:26 error Missing space before function parentheses space-before-function-paren
4:52 error Missing space before function parentheses space-before-function-paren
4:77 error Use the rest parameters instead of 'arguments' prefer-rest-params
4:93 error Expected this semicolon to be at the beginning of the next line semi-style
6:14 error Missing space before function parentheses space-before-function-paren
7:45 error 'define' is not defined no-undef
8:20 error 'define' is not defined no-undef
8:39 error Missing space before function parentheses space-before-function-paren
9:17 error Return statement should not contain assignment no-return-assign
12:13 error Return statement should not contain assignment no-return-assign
14:13 error Return statement should not contain assignment no-return-assign
16:25 error Strings must use singlequote quotes
16:78 error Missing space before function parentheses space-before-function-paren
17:41 error Expected this semicolon to be at the beginning of the next line semi-style
19:31 error Missing space before function parentheses space-before-function-paren
20:32 error Missing space before function parentheses `space-before-function-paren````
I'm using i18n as a frontend dependency using legacy syntax (load into global scope as i18n
).
When I run
let translator = i18n.create({values: {k1: 'v1'}})
translator.extend((a, b, c, d) => {return 'example extension'}) // fails here
I see
TypeError: translator.extend is not a function
So it appears that the extension syntax as documented will not work.
Hello,
In the ADM compliant version of 18n.js (downloaded here: http://i18njs.com/js/i18n.amd.js) there is a line:
self = i18n
which causes breakage in IE8. the self variable seems to be the outermost window. I don't believe you can overwrite window, so I'm a little confused as to what that line of code should do, but commenting it out seems to have no averse effects.
As I wrote here, I wrote Python implementation of this great library. What came to my mind during development, is that it would be very nice to have an official JSON Schema.
https://json-schema.org/understanding-json-schema/
This way not only we will have the syntax of the dictionaries officially standardized, but also IDE like Visual Studio Code, will be able to "understand" the syntax of the dictionary.
This will require 2 things:
A.d. 1
I can help with it.
A.d. 2
The question is, do we want to keep it in this repo (as the original one), or in a separate repo?
It would be awesome if the address could be something like http://i18njs.com/schema.json
But I don't know what do you think about it?
Br,
Marek
Hello,
I've been trying the library out and can't seem to get the contexts to work. I have tried with the examples provided in the docs with no luck:
{
"values":{
"Yes": "Yes",
"No": "No"
},
"contexts":[
{
"matches":{
"gender":"male"
},
"values":{
"%{name} updated their profile": "%{name} updated his profile"
}
},
{
"matches":{
"gender":"female"
},
"values":{
"%{name} updated their profile": "%{name} updated her profile"
}
}
]
}
And then:
console.log(i18n("%{name} updated their profile",
{
name: "Jane"
},
{
gender: "female"
}
));
Which ouputs Jane updated their profile
. The expected is Jane updated her profile
, if I'm not mistaken. I have also tried removing the %{name}
variable, but still not working.
Thank you.
Hey Simon,
Have you considered this awesome library as a package on npmjs.org? Would love to use it on my project, which uses NPM as the package manager.
Edi
It would be nice to do releases: https://github.com/roddeh/i18njs/releases
So dev using your lib is informed about current released version.
Hello,
under which license is this project released?
I could not find any information within the repository or the linked website.
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.