claudetech / node-static-i18n

HTML static pages i18n tool
https://www.npmjs.com/package/static-i18n
MIT License
102 stars 21 forks source link

Apply to file instead of folder #21

Open alvarotrigo opened 6 years ago

alvarotrigo commented 6 years ago

It would be great if we could apply the static-i18n command to a single file instead of to a folder.

I personally have my index.html file in the root path, and I would prefer to keep it that way because that's gonna be the structure in my hosting.

Right now I'm forced to place it within a folder so static-i18n can work over it, therefore messing my relative paths when outputing the result in a 2 levels depth path.

From ./www/index.html to i18n/es/index.html.

The other option would be to be able to configure the output path, so instead of having i18n/es/index.html we could have es/index.html and therefore solving the relative paths issue.

danhper commented 6 years ago

Thanks for reporting. I will look into it soon. By the way, if it can help you contributing I'm perfectly fine switching to plain JS instead of CoffeeScript.

alvarotrigo commented 6 years ago

By the way, if it can help you contributing I'm perfectly fine switching to plain JS instead of CoffeeScript.

How did you know I work with plain JS? :D Yeah, I never used coffescript before

danhper commented 6 years ago

How did you know I work with plain JS? :D

Your profile spoke for itself 😄 CoffeeScript kind of made sense when I started the project years ago, but not really anymore. Hopefully it should not be too hard to transform this to JS. Unless this and the other issues you raised are urgent, let's start by transforming this to JS before fixing the rest.

alvarotrigo commented 6 years ago

Hopefully it should not be too hard to transform this to JS.

The node module is already generated in .js. So we can just take that as the base?

danhper commented 6 years ago

The node module is already generated in .js. So we can just take that as the base?

Yes, the code is not really pretty so it will need a bit of work, but it is more or less usable.

danhper commented 6 years ago

I finished changing everything to JS and published a beta version to npm. It worked with my projects, but it would be great if you could give it a try, thanks.

Concerning this issue, you can already run static-i18n on a single file by using the --files options, for example

static-i18n -l en -i en -i fr --files 'index.html' .

If you want to configure the output path, you can use --output-dir as follow:

static-i18n -l en -i en -i fr www --output-dir .

Let me know if any of these option would work for your use case.

alvarotrigo commented 6 years ago

This is not working for me:

static-i18n -l en -i en -i es -i ru -i ko -i zh --fileFormat yml --allowHtml true --files 'demo.html'

I'm getting:

usage: static-i18n [options] directory

alvarotrigo commented 6 years ago

Ok, I had to add the . at the end

static-i18n -l en -i en -i es -i ru -i ko -i zh --fileFormat yml --allowHtml true --files 'demo.html' .

I'm using a file within a folder, so 'www/demo.html' . ends up creating i18n/es/www/demo.html instead of i18n/es/demo.html.

I tried using the --output-dir . param, but I get

usage: static-i18n [options] directory

With

static-i18n -l en -i en -i es -i ru -i ko -i zh --fileFormat yml --allowHtml true --files 'www/demo.html' --output-dir .
danhper commented 6 years ago

If your files are in the current directory, your first command is correct, but if they are in the www directory, it should be

static-i18n -l en -i en -i es -i ru -i ko -i zh --fileFormat yml --allowHtml true --files 'demo.html' www

For your second command, you are missing the input directory, as the final . is interpreted as the output directory. If you want to use the files in www as input, just append www to your last command.

static-i18n -l en -i en -i es -i ru -i ko -i zh --fileFormat yml --allowHtml true --files 'demo.html' --output-dir . www