Giter VIP home page Giter VIP logo

Comments (9)

eweap avatar eweap commented on July 28, 2024 2

@martinroob @martinsik Can't we add a pretty-xml call on the output before writing in the final xlf file ? (@martinroob thanks for your work btw !)

from ngx-i18nsupport.

martinroob avatar martinroob commented on July 28, 2024 2

This should be possible. I will have a look at it

from ngx-i18nsupport.

evanliomain avatar evanliomain commented on July 28, 2024 1

@martinsik I'm confronted to the same issue. I solve this by apply a little home made js script on the xlf files :

const replace = require('replace-in-file');
const format = require('xmlfmt');
const fs = require('fs');
const xlfFilesPath = 'src/i18n/*.xlf';

// Remove leading and trailing whith space
const filesChanges1 = replace.sync({
  files: xlfFilesPath,
  from: [/^\s*/gm, /\s*$/gm],
  to: ''
});

// Remove \n to put all in 1 line
const filesChanges2 = replace.sync({
  files: xlfFilesPath,
  from: /\n/gm,
  to: ''
});

// Format xml files
[
  'src/i18n/messages.xlf',
  'src/i18n/messages.en.xlf',
  'src/i18n/messages.fr.xlf'
].forEach(file => {
  fs.writeFileSync(file, format(fs.readFileSync(file, 'utf8')));
});

It need replace-in-file and xmlfmt to work.

from ngx-i18nsupport.

martinroob avatar martinroob commented on July 28, 2024 1

Starting with version 0.16.0 there is a new configuration parameter beautifyOutput. When it is set to true now pretty-data (the library beyond pretty-xml) will be used to format the output.

from ngx-i18nsupport.

martinroob avatar martinroob commented on July 28, 2024

Hi,
in principle you are absolutely right.
Unfortunately the output is just what the library I use for xml handling (xmldom) gives.
There is no good formatter available at the moment. At least I do not know one.
So I am sorry that I cannot correct this. Maybe later.
Instead of translating manually by editing the ugly xml file you should think about using a translation tool (TinyTranslator is the one I suggest if course)

from ngx-i18nsupport.

martinsik avatar martinsik commented on July 28, 2024

@evanliomain I ended up using the following command to prettify the output:

npm i --save-dev pretty-xml

And then the following:

cat src/locale/messages.zh.xlf | node node_modules/.bin/pretty-xml > src/locale/messages.zh.xlf-new && rm src/locale/messages.zh.xlf && mv src/locale/messages.zh.xlf-new src/locale/messages.zh.xlf

from ngx-i18nsupport.

eweap avatar eweap commented on July 28, 2024

@martinroob Awesome ! Thanks a lot !

from ngx-i18nsupport.

TrueOleg avatar TrueOleg commented on July 28, 2024

@martinsik I'm confronted to the same issue. I solve this by apply a little home made js script on the xlf files :

const replace = require('replace-in-file');
const format = require('xmlfmt');
const fs = require('fs');
const xlfFilesPath = 'src/i18n/*.xlf';

// Remove leading and trailing whith space
const filesChanges1 = replace.sync({
  files: xlfFilesPath,
  from: [/^\s*/gm, /\s*$/gm],
  to: ''
});

// Remove \n to put all in 1 line
const filesChanges2 = replace.sync({
  files: xlfFilesPath,
  from: /\n/gm,
  to: ''
});

// Format xml files
[
  'src/i18n/messages.xlf',
  'src/i18n/messages.en.xlf',
  'src/i18n/messages.fr.xlf'
].forEach(file => {
  fs.writeFileSync(file, format(fs.readFileSync(file, 'utf8')));
});

It need replace-in-file and xmlfmt to work.

Thanks

from ngx-i18nsupport.

JanneHarju avatar JanneHarju commented on July 28, 2024

Just here to say that I was totally missed this parameter. At least I found it now. This is gold. I was really frustrating with earlier dirty style how those files looks like. It was really hard to merge files and read them and edit them because there were several translations all in one line. Thank you for this feature.

from ngx-i18nsupport.

Related Issues (20)

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.