Coder Social home page Coder Social logo

i18njs's Introduction

i18njs

Internationalisation library for JS projects

For more information, demo and examples please checkout http://i18njs.com

Available via npm as npm install roddeh-i18n

Use with TypeScript

i18njs comes with typings for TypeScript. To use these typings in your project, they have to be imported explicitly. Simply create a *.d.ts file in your project folder and add the following content to it:

declare module "roddeh-i18n" {
  import i18n from "roddeh-i18n/typings";
  export default i18n;
}

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • Simon Rodwell - Initial work - roddeh

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

i18njs's People

Contributors

entriphy avatar ogallagher avatar roddeh avatar swionrdhw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

i18njs's Issues

[Idea] Support for num eq null

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

AMD compliant version of i18n.js does not work on IE8

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.

[Idea] Tool to work with i18n files

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?

[Idea] Linter

It would be nice to set up some rules and start using linter.

Lots of eslint errors (+140)

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````

Method extend does not exist on return value of i18n.create

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.

What about object notation?

locale:

  navbar: {
    menu: {
      listOfTutorials: 'List of tutorials',
    },
  },

I want to display t('navbar.menu.listOfTutorials')

but nothing happens

No maintaince

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.

[Idea][Standardization] JSON Schema

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:

  1. Of course writing the JSON Schema
  2. Publish it. It needs to be publicly accessible, so any IDE can fetch it right away.

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

[Idea] CI with Travis

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? :)

License unclear

Hello,

under which license is this project released?
I could not find any information within the repository or the linked website.

Pluralization rules

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

i18njs as NPM package

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

Contexts not working?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.