Js-lingui: Don't transform 褋yrillic to unicode by cli command `compile`

Created on 3 Feb 2019  路  16Comments  路  Source: lingui/js-lingui

The compile command transforms all Cyrillic text into Unicode sequences, which greatly increases the size of the code.
image

english text 9kb, russian 40kb.
image

If i keep my text in cyrillic, file size will be 10 kb
image

  • jsLingui version 2.7.3
  • Babel version 7.0.2

Most helpful comment

Please try to upgrade and check. There's also a codemod which makes the upgrade much easier. Unforutnately I don't have any source code with cyrillic

All 16 comments

Hey @dimensi,
this seems to be upstream issue: https://github.com/babel/babel/issues/4909

I think we could at least force UTF-8 characters in message catalogs. Want to take a look and submit a PR?

@tricoder42
Honestly, I was already thinking about pr, but I didn鈥檛 figure out where the code in general gets the text and is saved. So no matter how much I want, I can鈥檛 provide pr (

I believe we should add it here:

https://github.com/lingui/js-lingui/blob/master/packages/cli/src/api/compile.js#L172

but I'm not sure if jsonCompatibleStrings option is supported in babel-generator. The option is mentioned for docs in @babel/generator.

If not, we have to update the package and check if it works with babel 6 as well. Otherwise it's a breaking change and we have to wait for v3.

@tricoder42, I try set this property, it's not help.
this options from 6.19

@tricoder42 I read the entire issue of the link you gave. Unfortunately, only 7 versions of babel-generator can fix this. Need add

{ minified: true,
jsescOption: {
      minimal: true
    }
}

My temporary solution

const fs = require('fs')
const path = require('path')

const pathToFile = path.join(__dirname, 'src/locales/ru/messages.js');

const file = fs.readFileSync(pathToFile, 'utf8')

const r = /\\u([\d\w]{4})/gi

fs.writeFileSync(pathToFile, file.replace(r, function (match, grp) {
  return String.fromCharCode(parseInt(grp, 16))
}))

@tricoder42 any news?

The only news related to this issue is that the next version of LinguiJS is going to use Babel 7. I really don't know how to solve it in Babel 6.

Also have this problem. How I can help to fix it?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

waiting for this!

@max-mykhailenko Reading comments above, isn't it already fixed in Babel 7? Have you tried the latest LinguiJS version?

@tricoder42 Oh, I found that yesterday you released 3.0. Is the problem fixed there?

Update. Currently I use "@lingui/cli": "2.9.2" and problem still there

Please try to upgrade and check. There's also a codemod which makes the upgrade much easier. Unforutnately I don't have any source code with cyrillic

@tricoder42 May I ask to send me link to codemod? Nevermind, https://www.npmjs.com/package/@lingui/codemods

Alright, feel free to open a new issue with updated info if the problem still persists

Was this page helpful?
0 / 5 - 0 ratings