Skip to content

Creates angular-translate JSON and HTML with translate filter from HTML file with __content for translate__

Notifications You must be signed in to change notification settings

ibetovski/tr-create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tr-create

This project is focused mainly on angularjs projects using angular-translate.

Instalation

$ npm install -g tr-create

The Idea

Sometimes we are focused on the implementation and not on the copy text. We don't want our HTML/CSS/JS work to be bothered with the creation of the translate files for different languages. So we leave "Lorem ipsum" text or in my case "__text to be translated later__".

After the work is done, we run that script and it:

  • creates JSON files for translations (en.json or es.json) - if your JSON exists, we will merge the new content with the old one and will replace the existing file with the fresh content.
  • creates HTML file with {{ 'global.someText' | translate }} placeholder instead of __some text__

Usage

$ tr-create -s untranslated.html -t translated.html -l langs/en.json

Example:

untranslated.html content:

<!DOCTYPE html>
<html>
<head>
  <title>Example</title>
</head>
<body>
<div>__Please translate me__</div>
<h1>__I need a translation__</h1>
<p>__Please somebody to translate this text__</p>
</body>
</html>

execute:

tr-create -s untranslated.html

By default it will create:

  • en.json:
{
  "pleaseTranslateMe": "__Please translate me__",
  "iNeedATranslation": "__I need a translation__",
  "pleaseSomebodyToTranslateThisText": "__Please somebody to translate this text__"
}
  • untranslated_tr.html:
<!DOCTYPE html>
<html>
<head>
  <title>Example</title>
</head>
<body>
<div>{{'global.pleaseTranslateMe' | translate }}</div>
<h1>{{'global.iNeedATranslation' | translate }}</h1>
<p>{{'global.pleaseSomebodyToTranslateThisText' | translate }}</p>
</body>
</html>

Options

exmpale
tr-create -s [html_source_file] -l [language_json_file] -n [name_space]

-s,  --source
HTML file containig __text to translate__ dummy text

-r,  --replace
Replace the existing HTML with translations content

-n,  --name-space
Name space to be used in HTML translations: {{ 'nameSpace.textToBeTranslated' | translate }}

-l, --lang
Comma separated JSON file name for the languages.
You can provide full path if you need.
JSON extension will be added automatically if omitted
Example:
-l langs/en.json,langs/es.json
-l en,es

--ol, --only-language
Create only a language without HTML file

-t, --target-html
HTML file to be created with translation placeholders. If not specified we will create a new one with sufix.

-h, --help
Prints this help

MIT License

Contribute

If you have an idea or special needs that this tool doesn't cover don't hesitate to fork and add the needed feature. There is only one requirement - use ES6 and babel.

Changelog

v1.0.0

  • Changed -ol option to --ol
  • Added -r, --replace option - if set the existing HTML file provided by -s will be overwritten with the translations content
  • Multiple JSON files - comma separated: --lang en.json,es.json - or en,es (JSON extension will be added automatically if omitted)
  • Unit tests

v0.0.3

About

Creates angular-translate JSON and HTML with translate filter from HTML file with __content for translate__

Resources

Stars

Watchers

Forks

Packages

No packages published