Giter VIP home page Giter VIP logo

i18next-json-sync's People

Contributors

faulknercs avatar jwbay avatar regstar 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

Watchers

 avatar  avatar

i18next-json-sync's Issues

Fail check on empty keys

I have two scripts in my package.jsonfor this package.

"i18n": "sync-i18n --files src/assets/i18n/*.json --primary de --languages en --space 2 --newkeysempty",
"check-i18n": "npm run i18n -- --check"

i18n adds new keys to all other languages.
check-i18n checks for missing keys.

check-i18n should check if all keys are translated. But it doesn't fail for empty keys inserted by i18n.
Only for missing ones.

SyntaxError: Unexpected token  in JSON at position 0

I try run next command
node src/scripts/syncTranslateResources.js
where
scrypt is:
`const sync = require('i18next-json-sync').default;
try{

sync({
/** Audit files in memory instead of changing them on the filesystem and
* throw an error if any changes would be made /
check: false,
/
* Glob pattern for the resource JSON files /
files: 'src/assets/lang/
.json',
/** Primary localization language. Other language files will be changed to match /
primary: 'uk',
/
* Language files to create if they don't exist, e.g. ['es, 'pt-BR', 'fr'] /
createResources: [],
/
* Space value used for JSON.stringify when writing JSON files to disk /
space: 4,
/
* Line endings used when writing JSON files to disk. Either LF or CRLF /
lineEndings: 'LF',
/
* Insert a final newline when writing JSON files to disk /
finalNewline: false,
/
* Use empty string for new keys instead of the primary language value */
newKeysEmpty: false
})

}catch(e){
console.log(e);
}`
and every time get error:

SyntaxError: Unexpected token  in JSON at position 0 at JSON.parse (<anonymous>) at C:\Proj\AdSaver\LmsAdSaver\node_modules\i18next-json-sync\dist\LocalizationFolder.js:19:38 at Array.map (<anonymous>) at LocalizationFolder.populateFromDisk (C:\Proj\AdSaver\LmsAdSaver\node_modules\i18next-json-sync\dist\LocalizationFolder.js:17:57) at sync (C:\Proj\AdSaver\LmsAdSaver\node_modules\i18next-json-sync\dist\index.js:20:16) at Object.<anonymous> (C:\Proj\AdSaver\LmsAdSaver\src\scripts\syncTranslateResources.js:4:3) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

--newKeysEmpty 'true' doesnt work on package json script

"i18n": "sync-i18n --files 'src/app/i18n/*.json' --primary pt_br --languages es --space 4 --newKeysEmpty 'true'"

this is my configuration, but the new keys added to es.json still using primary language text, i want it to be empty;

End of lines and --check

can you add an option to have an end of line at the end of the localization files? I edit the keys manually and my editor automatically remove whitespaces and add an empty line at the end of the file, and the --check option fails because of that.

Feature Request: Add interpolation validation

Our translation team has been known to accidentally translate replacement tokens. It would be awesome if this lib could parse the format and consistency of interpolation tokens. Bonus points if we could support ICU plurals in the replacements; but, I realize this is probably an entirely different ticket and feature as it looks like i18n prefers the plural suffixes by default.

// en.json
{
"hello": "hello {{name}}"
}
// es.json
{
"hello": "hola {{nombre}}
}

Parsing seems to require finalNewline regardless of finalNewline option

The parsing of the json file seems to fail if there's a trailing newline and doesn't seem to consult the finalNewline option. I recognize the finalNewline is likely an output option, but would be great if we could have an option to control if it's allowed in the source translation files.

it's pretty common on *nix systems, editor configs, and IDE formatters to insert a trailing newline.

I actually had to remove --check from my command to format so I could find the issue.

npx sync-i18n --files '**/src/i18n/*.json' --primary "en-us" --space 4 --finalNewline true --check

Plurals are not handled properly, it is not aligned with i18next

For example,

// en.json
{
   "one": "singular message",
   "one_plural": "plural message"
}

Should be for he (Hebrew) synced as

// he.json
{
   "one": "singular message",
   "one_0": "singular message",
   "one_1": "singular message",
   "one_2": "plural message",
   "one_3": "plural message",
}

Currently the sync will produce

// he.json
{
   "one": "singular message",
   "one_plural": "plural message"
}

For more details there is a playground that demonstrates it
It probably related to https://github.com/i18next/i18next/blob/master/src/PluralResolver.js

Should language files get translated?

Hi,

I created the node.js file with the default parameters. I'm using typescript so I have this script in package.json:
"i18n": "ts-node ./scripts/node.js"

This runs fine and generates the language files, but the language files are still in english. How can I get it to automatically translate the new keys to the proper language?

Option to preserve key ordering of primary json

Hi, this package looks very useful, but unfortunately it is reordering all my JSON keys into alphabetical order. So my en.json got changed to, for example,

    "april": "April",
    "august": "August",
    "december": "December",
    "february": "February",
    "january": "January",
    "july": "July",
    "june": "June",
    "march": "March",
    "may": "May",
    "november": "November",
    "october": "October",
    "september": "September"

I would much prefer to preserve the ordering in en.json which is logical and therefore helps the translator to translate. Can we have an option for this? Based on the example in your documentation, I did not expect the keys to reorder.

An option to disable sorting keys?

In some particular scenario, ordered keys are required. I found i18next-json-sync will change the keys' ordering; I digged the code but don't know where it sort key nor know why it can.

A suggestion about the option:

sortKeys: 'followPrimaryLang' | 'always'

shebang line not working with crlf

cli.ts and dist/cli.js have CRLF (Windows) line ending instead LF (Unix)

#!/usr/bin/env node

So it impossible to run script from package.json

{
  "name": "my-app",
  "scripts": {
    "i18n": "sync-i18n --files '**/locales/*.json' --primary en --languages es fr ja zh ko --space 2",
    "check-i18n": "npm run i18n -- --check"
  }
}
$ yarn i18n

/usr/bin/env: ‘node\r’: No such file or directory

Temporary solution - execute sync-i18n directly:

{
  "name": "my-app",
  "scripts": {
    "i18n": "node node_modules/.bin/sync-i18n --files '**/locales/*.json' --primary en --languages es fr ja zh ko --space 2",
    "check-i18n": "npm run i18n -- --check"
  }
}

I suggest this TODO list to improve repo:

OS: Arch Linux
Node.js: 10.7.0
Yarn: 1.9.2
i18next-json-sync: 2.2.0 (latest)

Plural recognition in translation files with country codes

Hello,

Thanks for this tool, it helps us a lot, but I found the next issue with plurals recognition:

When we have filenames with country codes (en-US.json and ru-RU.json), i18next-json-sync doesn't correctly recognize language plurals for ru-RU and removes key_0 and other plural keys from it. It pushes key_plural instead, which is incorrect for ru-RU language. Looks like, it doesn't work, when there is - character in file name.

primary: 'zh' will don't work

sync({
/** Audit files in memory instead of changing them on the filesystem and
* throw an error if any changes would be made /
check: false,
/
* Glob pattern for the resource JSON files /
files: './js/i18n/languages/
.json',
/** Primary localization language. Other language files will be changed to match /
primary: 'zh',
/
* Language files to create if they don't exist, e.g. ['es, 'pt-BR', 'fr'] /
createResources: ['fr'],
/
* Space value used for JSON.stringify when writing JSON files to disk /
space: 4,
/
* Line endings used when writing JSON files to disk. Either LF or CRLF */
lineEndings: 'LF'
})

sync en.json will be {} , is empty;

primary: 'zh' is fine

Problem with wildcards in the CLI example on OSX

When using wildcards in package.jsonas shown in the CLI example, globbing behaves unpredictably on OSX. In my case, I used --files wwwroot/locales/*.json. When run from the CLI, this caused globbing to be handled by the shell instead of Node, strangely enough resulting in the script only finding the first file in the folder.

Escaping the wildcards ensures that globbing is handled by Node, avoiding the unpredictability. Thus, the example should look like this:

"i18n": "sync-i18n --files \\*\\*/locales/\\*.json --primary en --languages es fr ja zh ko --space 2"

Config file support

Instead of having to run
sync-i18n --files '**/locales/*.json' --primary en --languages es fr ja zh ko --space 2

It would be nice to be able to run
sync-i18n i18next-json-sync.config.js

Where i18next-json-sync.config.js would be:

module.exports = {
  files: '**/locales/*.json',
  primary: 'en',
  createResources: ["en", "fr", "ja", "zh", "ko"],
  space: 2
}

Can't get it to work with namespaces

Hi
My files are organized in namespaces like this

  • en
    • about.json
    • help.json
  • fr
    • about.json
    • help.json

How can i use this setup with your tool? I can't get it to work

Spaces are replaced with the literal text "4"

If I run npx sync-i18n --files ./locale/*.json --primary en --space 4, my JSON ends up looking like this:

{
4"_name": "English"
}

rather than

{
    "_name": "English"
}

This does not happen on 2.3.1, but happens on any newer version.

i18next-json-sync file sync question

I am new to this package and am trying to use it to sync different language files for my angular2/nodejs project. But the given usage is not working for me.

My lang file structure is (multiple levels deep):

  • package.json
  • public
    • app
      • assets
        • language
          • en.json
          • es.json
          • fr.json
          • ja.json

And my package.json has:

{ 
  "scripts": {
   ...
   "i18n": "sync-i18n --files './public/app/assets/language/*.json' --primary en --languages es fr ja",
   "check-i18n": "npm run i18n -- --check",
   ...
}
 "devDependencies": {
    ...
    "i18next-json-sync": "2.2.0",
    ...
  }
}

But when I run npm run check-i18n or npm run i18n I do not see any key/values being copied from en file (primary) to other language files. What am I missing?

Folder namespace support

@jwbay Does this package support folder namespace support? For example:

examples
├── en
│   └── namespace.json
├── de
│   └── namespace.json
└── es
    └── namespace.json

Thanks in advance

Doesn't copy non-plurals correctly when a certain number of plurals are present

en.json

{
	"one": "one",
	"two": "two",
	"two_plural": "two_plural",
	"three": "three",
	"three_plural": "three_plural"
}

de.json

{
	"two": "two",
	"two_plural": "two_plural",
	"three": "three",
	"three_plural": "three_plural"
}

ja.json

{
	"two": "two",
	"three": "three",
}

After syncing, one is only added to ja, when it should be added to de as well. Only happens with two plurals, so a comparison with plural form count is likely going wrong somewhere in 24abe89

	function targetPluralsPopulated(target, key) {
		//given 'x' for key, do we have 'x' and 'x_plural' for en?
		return (
			Object.keys(target).filter(function(targetKey) {
				return keyMatchesPluralForLanguage(targetKey, targetLanguage);
			}).length === getPluralsForLanguage(targetLanguage).length
		);
	}

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.