i18next / i18next-parser Goto Github PK
View Code? Open in Web Editor NEWParse your code to extract translation keys/values and manage your catalog files
License: MIT License
Parse your code to extract translation keys/values and manage your catalog files
License: MIT License
For another i18n library I'm trying to use in combination with this (awesome) scanner, it's required the JSON files are in a structure like i18n/en.i18n.json
. However, it seems besides the folder the files are placed I have no ability to tweak the file naming of the generated JSON files. I have browsed through the source, but cannot find if/how to do this. Is this possible, and if not, could it be made possible you think?
As described in http://i18next.com/pages/doc_templates.html, to use context and option variables in Handlebars, we need an extended helper
Handlebars.registerHelper('tr', function(context, options) {
var opts = i18n.functions.extend(options.hash, context);
if (options.fn) opts.defaultValue = options.fn(context);
var result = i18n.t(opts.key, opts);
return new Handlebars.SafeString(result);
});
Is it sensible to support this along with the standard t
?
Hi,
while trying to parse all meteor app folder got such a mistake:
[parse] /home/username/.meteor/packages/webapp/.1.1.6.6iir9q++os+web.browser+web.cordova/npm/node_modules/connect/node_modules/multiparty/node_modules/readable-stream/test/simple/test-stream2-writable.js
fs.js:113
throw er;
^
Error: Path must be a string without null bytes.
at nullCheck (fs.js:111:14)
at Object.fs.openSync (fs.js:501:3)
at Object.fs.writeFileSync (fs.js:1103:15)
at Transform._transform (/usr/lib/node_modules/i18next-parser/bin/cli.js:125:12)
at Transform._read (/usr/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at Transform._write (/usr/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/usr/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:238:10)
at writeOrBuffer (/usr/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:228:5)
at Transform.Writable.write (/usr/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:195:11)
at Parser.ondata (_stream_readable.js:540:20)
With default gulp setup as
Gulpfile.coffee
gulp.task 'i18n', ->
gulp.src 'src/features/**/*.html'
.pipe i18next {locales: ['en', 'de', 'ru', 'en-US'], output:'translation.json'}
.on 'reading', (file)->
console.log 'looking for $.i18n.t function with keys in ' + file
.pipe gulp.dest 'src/locales'
it completely overrides whole directories without even saving the old keys.
What is wrong? How do I keep old keys + keeping my actual values.
it overrides with empty values.
This guide can be followed to migrate away from gulp-util: https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
Suppose I have a key 'foo_bar' in my application and it is currently translated for locale EN but not for FR, ES (which are also supported locales in this app). The parser will grab the value from the EN locale and apply that value to FR, ES parsed locales.
I am trying to use the i18next-parser as a coverage report tool to see what key-value pairs still need translations for other locales other than our default english one. I was expecting keys that do not have have a translation in a particular locale to be parsed by the tool with an empty string as it's default value.
locales
│
└─── en
│ └─── translation.json
│
└─── fr
│ └─── translation.json
│
└─── es
└─── translation.json
original locales file
locales/en/translation.json = {"foo_bar": "test translation", "welcome": "hello"}
locales/fr/translation.json = {"welcome": "bonjour"}
locales/es/translation.json = {"welcome": "hola"}
parsed locales file
locales/en/translation.json = {"foo_bar"": "test translation", "welcome": "hello"}
locales/fr/translation.json = {"foo_bar": "", "welcome": "bonjour"}
locales/de/translation.json = {"foo_bar": "", "welcome": "hola"}
parsed locales file
locales/en/translation.json = {"foo_bar": "test translation", "welcome": "hello"}
locales/fr/translation.json = {"foo_bar": "test translation", "welcome": "bonjour"}
locales/de/translation.json = {"foo_bar": "test translation", "welcome": "hola"}
Idea 1
Have a file keys.json
with translation keys we want to force or remove in the library:
{
add: {
namespace: {
parent_key: {
child_key: ""
}
}
},
removeEmpty: true,
remove: {
namespace: {
bla: ""
}
}
}
We could also have a file per namespace : translation_keys.json
, namespace_keys.json
...
fs.js:427
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: EMFILE, too many open files '/me/project/app/assets/locales/en/translation.json'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at Parser._flush (/me/project/node_modules/i18next-parser/index.js:154:54)
at Parser.<anonymous> (_stream_transform.js:130:12)
at Parser.g (events.js:175:14)
at Parser.EventEmitter.emit (events.js:92:17)
at finishMaybe (_stream_writable.js:354:12)
at endWritable (_stream_writable.js:361:3)
at Parser.Writable.end (_stream_writable.js:339:5)
at Stream.onend (stream.js:79:10)
at Stream.EventEmitter.emit (events.js:117:20)
at end (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:116:39)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:62:17)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:56:14)
at next (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:71:7)
at /me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:85:7
at /me/project/node_modules/gulp/node_modules/vinyl-fs/lib/src/bufferFile.js:8:5
at fs.js:266:14
at /me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/graceful-fs/graceful-fs.js:105:5
at Object.oncomplete (fs.js:107:15)
Version: 1.0.0-beta-6
I'm not sure if this is a bug (not handling all quote formats) or a feature (handling new quote format).
This gets parsed properly:
t('Hello world')
Neither of those gets parsed:
t(`Hello world`)
t(`Hello ${name}`)
Config file:
{
"keySeparator": "__NO_KEY_SEPARATOR__",
"namespaceSeparator": "|",
"lexers": {
"js": ["JavascriptLexer", "JsxLexer"]
},
"reactNamespace": true,
"sort": true,
"locales": ["en", "fr"]
}
Usage through cli.
I'm using your tools to automatize the translation process. Like to say thank you at first.
I'd like to share some nice to have features for the future.
Hope it was helpful.
Can't seem to get this to work. I'm on win7 using version 0.3.4. Throws an error trying to read in the locales dir. It will create the dir and leave it empty.
C:\l2>i18next "C:\l2"
i18next Parser
--------------
Input: C:\l2
Output: C:\l2\locales
[parse] C:\l2\i18next-1.7.4.js
[parse] C:\l2\index.html
fs.js:432
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT, no such file or directory 'C:\l2\locales\en\,
reuseSuffix.json'
at Object.fs.openSync (fs.js:432:18)
at Object.fs.writeFileSync (fs.js:971:15)
at Transform._transform (C:\Users\user\AppData\Roaming\npm\node_modules\
i18next-parser\bin\cli.js:127:12)
at Transform._read (C:\Users\user\AppData\Roaming\npm\node_modules\i18ne
xt-parser\node_modules\through2\node_modules\readable-stream\lib\_stream_transfo
rm.js:184:10)
at Transform._write (C:\Users\user\AppData\Roaming\npm\node_modules\i18n
ext-parser\node_modules\through2\node_modules\readable-stream\lib\_stream_transf
orm.js:172:12)
at doWrite (C:\Users\user\AppData\Roaming\npm\node_modules\i18next-parse
r\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:237
:10)
at writeOrBuffer (C:\Users\user\AppData\Roaming\npm\node_modules\i18next
-parser\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.
js:227:5)
at Transform.Writable.write (C:\Users\user\AppData\Roaming\npm\node_modu
les\i18next-parser\node_modules\through2\node_modules\readable-stream\lib\_strea
m_writable.js:194:11)
at write (_stream_readable.js:585:24)
at flow (_stream_readable.js:594:7)
C:\l2>
Hi,
I try to parse next code in .js file:
i18n.t("Change lang 2");
I've tried
[mainuser@mainuser:~]$i18next ~/my-app/client/ -r -l en,ru,ua -f t,tt,i18n.t
and
[mainuser@mainuser:~]$i18next ~/my-app/client/ -r -l en,ru,ua -f t,tt
both do nothing with that code form .js file.
What I'm doing wrong?
Thanks a lot, Karel! This awesome parser helps me a lot!
I noticed a small difference between i18next and this library regarding the option names - i18next uses nsSeparator
, whereas i18next-parser uses namespaceSeparator
.
We should probably check other option names as well.
0.x
or 1.x
)?
I try to extract json files from react-i18next examples (react_withHOC & react_renderProps)
Here is my config file:
// i18next-parser.config.js
module.exports = {
reactNamespace: true,
locales: ['en', 'de'],
output: './locales'
};
The command I'm running:
i18next "src/**/*.{js,jsx}" -c ./i18next-parser.config.js
both en
and de
are
// translation_old.json
{}
// translation.json
{
"title": "",
"description": {
"part2": ""
}
}
Need to extract the text from <Trans>
too. But description.part1
key is missing.
{
"title": "",
"description": {
"part1": "",
"part2": ""
}
}
Under which license is this code published? MIT? Apache-2.0?
Hey,
I have a problem understanding how the parser handles plural forms.
Ordinarily, I would crate a plural key in the following way
{
"contacts" : "__total__ contact",
"contacts_plural" : "__total__ contacts"
}
And use it in a script via i18n.t('contacts', {total: total})
, with the plural selected by i18next according to the value of total
.
The parser does not detect such usages (I get only a "contacts" key in the outputted JSON). (I don't see how it could, in fact, detect these and distinguish them from translations that are just parameterized). Is there a special syntax I should be using so the parser can detect plurals that are declared in this fashion?
Moreover, in this parser unit test it appears to know that the second plural should have a special form for the value "12". How is this determined from the input text "asd t('test_plural:first') t('test_plural:second')"
?
You can use false
to disable separators in 18next. I think this library should behave the same way.
We are trying to keep our translations in "real" english to have a acceptable fallback if a string isn't translated (Do you want to continue ?
looks better than modal.question.continue
when the string is not available in your language at the moment).
i18next doesn't handle i18n.t('From', { context: 'date' })
but i18n.t('From::date')
. It's an issue when you rely on key for fallback.
I quickly look at the code, and it seems we don't get any options atm.
This example from the readme.md does not appear to be working in the cli:
i18next /path/to/file/or/dir -filterFolder *.hbs,*.js -filterFolder !.git
Whenever I try to exclude a folder I get this error:
-bash: !.git: event not found
Scanning
i18n.t(prefix + param);
Will result in:
[exec] [error] i18next-parser does not support variables in translation functions, use a string literal: t(prefix + param)
Version 0.7.0 or lower doesn't have this issue.
Is this construction is deliberately not supported anymore or did something break ?
btw thanks for this great scanner !
Hello, it's me again.
Was wondering, maybe I am doing something wrong, but the values in the translation.json file which I filled out manually are always overwritten by empty strings when I re-parse my html/js.
Is it a normal behavior, and if so, is it possible to keep the values somehow?
Thank you
Can't be much more descriptive than in the title. Here is a code snippet:
<div className="flex-item-m-2 recent-activity-item-footer">
<Interpolate i18nKey='Total {{amount}}' useDangerouslySetInnerHTML={true} amount={totalDocs} />
</div>
Sadly, the string 'Total {{amount}}' never makes it to the JSON output of the parser.
When data-i18n and data-i18n-options coexist in a DOM only data-i18n is recognized, suppose I wanted a translation with context, I couldn't get it with this tool
Keys are currently sorted alphabetically translation.json
:
{
"A": "a",
"B": "b",
"C": "c"
}
Would be nice to have the keys without order, as they appear inside the source code (e.g. in the order they are parsed):
{
"C": "c",
"A": "a",
"B": "b"
}
This way the keys follow the source code logic.
I even believe the "source code order" should be the default one and a --alphabetical-order
option should be added.
i18next-parser doesnt collect concatenated strings, e.g. i18n.t("Foo: " + "Bar")
. It would be awesome if it did.
i18n-extract does this, so maybe it won't be difficult to reimplement?
sometimes, we will use custom separator for namespace or keys, for the use '.' and ':' may conficit with some text string.
I have use this parser for ourr project,and thanks for your greate job! In practice, we just encounter above problem.So I readed the source code,and add custom separator for our convienience.Also I fork it to my repositories, and commit my fix.
I'd like to share my fix to other people too.Can you check my code and apply this fix,please!
As already partially discussed in #13 and related to my implementation as described here http://stackoverflow.com/questions/26561879/i18next-best-practice/26737839?noredirect=1, I wonder if it will be possible to:
Parse i18n.t('namespace.example', 'Default value');
methods and insert Default value
into the locales/translation files whenever namespace.example
is still empy. And do the same for <span data-i18n="namespace.example">Default value</span>
HTML tags.
I think it is way more easy to translate a JSON file that looks like:
"namespace" : {
"example" : "Default value"
}
Than when it looks like:
"namespace" : {
"example" : ""
}
Assuming that my implementation works correctly. My generated translation files always contain empty strings like in the latter example.
As a side benefit; then even when a lable is untranslated, the UI will at least show the default value (in most cases the English version) instead of an empty string.
Hello there, i have this problem i am using the cli with this command:
i18next "src/**/*.js" -o . -l en,de
and i get ./locales/en and ./locales/fr
Is there an issue with the german language or am i doing something wrong
Thank you
Error log:
undefined:0
^
SyntaxError: Unexpected end of input
at Object.parse (native)
at Parser._flush (/me/project/node_modules/i18next-parser/index.js:154:44)
at Parser.<anonymous> (_stream_transform.js:130:12)
at Parser.g (events.js:175:14)
at Parser.EventEmitter.emit (events.js:92:17)
at finishMaybe (_stream_writable.js:354:12)
at endWritable (_stream_writable.js:361:3)
at Parser.Writable.end (_stream_writable.js:339:5)
at Stream.onend (stream.js:79:10)
at Stream.EventEmitter.emit (events.js:117:20)
at end (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:116:39)
at queueData (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:62:17)
at next (/me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:71:7)
at /me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:85:7
at /me/project/node_modules/gulp/node_modules/vinyl-fs/lib/src/bufferFile.js:8:5
at fs.js:266:14
at /me/project/node_modules/gulp/node_modules/vinyl-fs/node_modules/graceful-fs/graceful-fs.js:105:5
at Object.oncomplete (fs.js:107:15)
having done: https://github.com/i18next
so if anyone want to move his i18next related project contact me - so we could plan that.
let's discuss this: i18next/i18next#99
If JSON.parse
crashes, so does the parser.
SyntaxError: Unexpected end of input
at Object.parse (native)
at Parser._flush (/Users/kalema/Sites/BookMyCoach/bmc_frontend/node_modules/i18next-parser/index.js:154:44)
Looks like this parser doesn't support context
example:
{
"key": "text",
"key_male": "text male",
"key_female": "text female",
"key_male_plural": "text __count__ male"
}
in html
$.i18n.t("key", {context: "male"})
it will delete keys with male and female and move it to _old.json
When parser runs at the end of the generated file the newline is cut. It ends immediately after the closing bracket.
Hi,
thank you for awesome step towards i18next translation easiness!!!
However here is what I got on my 12.04 Ubuntu:
[mainuser@mainuser:~/test-app]$i18next ~/test-app/client/ -r -l en -f t,tt
Target: /home/mainuser/test-app/client
Output: undefined
[parse] /home/mainuser/test-app/client/changeLang.html
[parse] /home/mainuser/test-app/client/changeLang.js
[parse] /home/mainuser/test-app/client/client.js
[parse] /home/mainuser/test-app/client/contact.html
[parse] /home/mainuser/test-app/client/contact.js
[parse] /home/mainuser/test-app/client/error.html
[parse] /home/mainuser/test-app/client/footer.html
[parse] /home/mainuser/test-app/client/header.html
[parse] /home/mainuser/test-app/client/home.html
[parse] /home/mainuser/test-app/client/how-it-works.html
[parse] /home/mainuser/test-app/client/index.html
[parse] /home/mainuser/test-app/client/loading.html
[parse] /home/mainuser/test-app/client/dashboard/adminPanel.html
[parse] /home/mainuser/test-app/client/dashboard/borrow.html
[parse] /home/mainuser/test-app/client/dashboard/dashboard.html
[parse] /home/mainuser/test-app/client/dashboard/dashboard.js
[parse] /home/mainuser/test-app/client/dashboard/haveToRegister.html
[parse] /home/mainuser/test-app/client/dashboard/lend.html
fs.js:427
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT, no such file or directory '/home/mainuser/test-app/locales/en/translation.json'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.writeFileSync (fs.js:966:15)
at Transform._transform (/home/mainuser/.nvm/v0.10.22/lib/node_modules/i18next-parser/bin/cli.js:100:12)
at Transform._read (/home/mainuser/.nvm/v0.10.22/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:179:10)
at Transform._write (/home/mainuser/.nvm/v0.10.22/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:167:12)
at doWrite (/home/mainuser/.nvm/v0.10.22/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:229:10)
at writeOrBuffer (/home/mainuser/.nvm/v0.10.22/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:219:5)
at Transform.Writable.write (/home/mainuser/.nvm/v0.10.22/lib/node_modules/i18next-parser/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:186:11)
at write (_stream_readable.js:583:24)
at flow (_stream_readable.js:592:7)
How to fix / avoid that?
Thanks a lot!
Hey,
I've found that the parser cannot handles translation keys of the following form
i18n.t('Lorem ipsum dolor sit \'amet\'.');
The parser will hang if a file containing this string is passed to it. The problem is the final dot; remove this and the parse works correctly.
The issue is in the regular expression on line 99 of index.js
. For the function i18n.t
it creates the following regex
[^a-zA-Z0-9_](?:(?:i18n\.t))(?:\(|\s)\s*(?:(?:'((?:(?:\\')?[^']+)+[^\\])')|(?:"((?:(?:\\")?[^"]+)+[^\\])"))
With this regex, you can see the problem here http://www.regexr.com/39p62 We get a timeout; remove the dot (or add characters after it) and we get 1 match.
I'll try to have a look at the regex tomorrow and see if I can resolve the problem; debugging regexes aren't really my forté though, so I thought I'd raise it here first :)
I noticed that strings with \n
get converted to \\n
in the output files :(
Version: 1.0.0-beta-6
I'm using "keySeparator": false
so I can use strrings rather than key: t('Hello! How are you?')
instead of t('welcome.message')
.
The reason is so that this can be extracted: t('Logging in...')
. With keySeparator
set to false, the dots should not cause problems.
However doing that causes a bunch of weird files to popup: locales/en/translationfalseKey1.json, locales/en/translationfalseKey2.json, ... One different file per language and per individual key.
Here is my JSON:
{
"keySeparator": false,
"namespaceSeparator": false,
"lexers": {
"js": ["JavascriptLexer", "JsxLexer"]
},
"sort": true,
"locales": ["fr","en"]
}
Here is how I call with the cli: i18next 'app/**/*.js' -c locales/i18next-parser.config.json -o .
Current workaround: use something like "__NO_KEY_SEPARATOR__"
instead of false
.
E.g. in this string
// TODO would be good to not include nodes that weren't in the defaults parameter
The function added to index.js in this commit finds a match and outputs an "i18next-parser does not support variables in translation functions" error.
match[1] is "t in the defaults parameter"
I'm using i18next with React (react-i18next), and this parser is working fine, except that the i18next keys are the same as the content. Like this example.
Right now, when I run the parser, the new keys stores empty values in the JSON files, as default and I have to copy / paste the key to the value. Is there any way to set the value to the same as the key?
Another nice feature, would be to set a default value, so it's easier to see what hasn't been translated yet
{
"Hello world, this is some text": "",
"Another internationalized string": ""
}
{
"Hello world, this is some text": "Hello world, this is some text",
"Another internationalized string": "Another internationalized string"
}
{
"Hello world, this is some text": "__UNTRANSLATED_VALUE__",
"Another internationalized string": "__UNTRANSLATED_VALUE__"
}
1.0.0-beta6
cli
I'm trying to use Trans
component as self-closing tag.
<Trans i18nKey="Foo" />
CLI just do nothing without any error.
<Trans i18nKey="Foo"></Trans>
This works fine
Hello,
I am trying to parse 'data-i18n' attributes from html files with custom regex:
i18next modules/ -o lang/ -r '[^a-zA-Z0-9](?:(?:t)|(?:i18n\\.t)|(?:data-i18n))(?:\\(|\\s|=)\\s*(?:(?:\'((?:(?:\\\\\')?[^\']+)+[^\\\\])\')|(?:"((?:(?:\\\\")?[^"]+)+[^\\\\])"))'
.
It doesn't seem to work. How to do it properly?
i'm using https://github.com/i18next/i18next-node-fs-backend with yaml files, is it possible for i18next-parser to output yaml files too instead for json?
Hello,
I'm trying to parse text with : (colon) inside it.
For example: "Hello, I have: one, two, three"
Parser will separate this into 2 strings. "Hello, I have" and "one, two, three".
Any suggestion how to handle this case (without splitting into separated strings)?
Thanks
If the key looks like: t('bla.'+variable)
, then the json
file get filed with an empty translation:
{
"bla": {
"": ""
}
}
Is this a bug or a feature request?
Bug
What version are you running (0.x
or 1.x
)?
1.0.0-beta9
Which runner (cli, gulp...)?
gulp
Extract translations from JS and HTML (pseudo handlebars templates) files
Here is my config (extracted from gulpfile.js):
{
locales: ['en', 'fr'],
output: '../locales',
functions: ['__'],
createOldCatalogs: false
}
The command I'm running:
gulp i18next
An error:
.../node_modules/i18next-parser/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import { dotPathToHash, mergeHashes, populateHash } from './helpers'
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (.../gulpfile.js:34:17)
My translations in output folder.
In this case, key goes undetected.
i18n.t('date: {{date}}',
{date: date},
{context: 'notifications'}
);
(I opened a related issue for the i18next-gettext-converter here: i18next/i18next-gettext-converter#55)
Wanting to add the functionality to track file path references to each key for the purpose of having those comments end up in .po files for our translators to get better context as-needed, requiring modifications both in this repo and in the i18next-gettext-converter, and curious how amenable you'd be to merging that sort of thing in?
I've been helping with some efforts to internationalize a medium-large size Ember app, and since gettext doesn't play nice with html and handlebars, we needed these two repos to generate our translation strings and convert between .json -> .po and vice versa.
But we ran into a slight issue, our translators will need file path references for each key, as comments in the .po files (something that gettext does by default in a typical i18n workflow, except gettext has line numbers, which we won't be needing) and although the gettext-converter does have some* ability to add comments, the data structure output by this tool doesn't keep track of those file paths.
Initially I modified the i18next-parser to output something that looks more like:
{
'some key': {
msgstr: '',
paths: ['app/templates/error.hbs', '../fake/path']
}
}
Where paths
is an array of each file path location that a given key is found at, in case you have the same key in multiple places in your source code.
rather than the current output:
{
'some key': ''
}
and I modified the gettext-converter to handle both formats dynamically while converting from .json -> .po, so you can have keys with file path information and others without, in the same file.
Currently, my little demo of this working involves either symlinking my local changes or pointing our app at my own forks of these two repos, which is less than ideal. I'm hoping to get these changes merged in at some point, so in the past couple days I've gone through and modified my code to use an additional flag '-t, --track-paths', so it generates the original data structure unless you include that flag and set it to true.
To further support our workflow, since the i18next runtime still needs the original format, I also made it so that using '--track-paths' will prepend '/tmp' to the output location of the translation file but not the translation_old file. So rather than running this tool to get our .json, and then running the converter to get our .po - we are running this tool with --track-paths true
to get our new .json format, then running the converter on the output /tmp/locales/en/translation.json to get our .po file, and finally running the converter a second time to go from .po -> .json so that we're back in the original format, and now back in the correct directory as well.
Ideally we'd like to merge these changes back into the repos, rather than maintaining our own forks. I'm doing my best to ensure that this is all opt-in behavior and that it doesn't affect any other workflows that people may be using. Just wanted to put the feelers out there before I get my PR's up. Any feedback is appreciated!
For example:
.my-title(t="home.title")
is not matched by attribute regex on line 144 of index.js
var attributeWithValueRegex = new RegExp( '(?:\\s+' + attributes + '=")([^"]*)(?:")', 'gi' );
the regex requires a preceding space (as is always the case in html)
suggested fix:
instead of space class \s
use non-word class \W
var attributeWithValueRegex = new RegExp( '(?:\\W+' + attributes + '=")([^"]*)(?:")', 'gi' );
Am sending test in PR.
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.