Skip to content

lvskng/polyglot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

              ______               ______     _____ 
_________________  /____  ________ ___  /_______  /_
___  __ \  __ \_  /__  / / /_  __ `/_  /_  __ \  __/
__  /_/ / /_/ /  / _  /_/ /_  /_/ /_  / / /_/ / /_  
_  .___/\____//_/  _\__, / _\__, / /_/  \____/\__/  
/_/                /____/  /____/                   

What is polyglot?

polyglot is a simple helper tool to manage your i18n files more efficiently.

How?

If your framework uses the i18n_.properties format of internationalization files (eg. SAP UI5, SAP MDK), this tool allows you to auto-generate them from a config file in a more freindly and human-readable syntax.

Which syntax?

polyglot uses the HCL (HashiCorp Configuration Language) format as an input and can generate the files in the i18n.properties format for you.

Example

i18n.hcl

langs = ["en", "fr", "de", "jp"]

#Declate 'en' to be the default language, optional
#If no default language is declared, the keyword 'default' is treated as such
default = "en"

#Define your translations as nested blocks
mainPage {
  #You can use labels to represent empty parent blocks
  header "title" {
    en = "Hello, world!"
    de = "Hallo, Welt!"
    fr = "Bonjour le monde!"
    #Full unicode support
    jp = "こんにちは、世界"
  }
  items {
    computer {
      #Use 'all' directive to define all words with the same string
      #Language names take precedence before all
      fr = "Ordinateur"
      jp = "コンピューター"
      all = "Computer"
    }
    wine {
      de = "Wein"
      en = "wine"
      fr = "vin"
      jp = "ワイン"
    }
  }
}

polyglot will generate a directory from the file looking like this:

i18n/
├── i18n.properties
├── i18n_de.properties
├── i18n_fr.properties
└── i18n_jp.properties

Notice that no i18n_en.properties is generated, since 'en' is the default language.

The HCL format is far more powerful than needed for this specific purpose, but has a more pleasant syntax than JSON or YAML. Other features of HCL might / should work as well, but are not tested yet.

Can I migrate existing projects to polyglot?

Yes! If you use the subcommand migrate, polyglot will read your existing i18n.properties files and create your i18n.hcl file for you. See help for more information.

How do I use it?

COMMANDS:
   generate, g  generate i18n files from hcl file
   migrate, m   migrate i18n files to hcl
   help, h      Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --separator string, -s string  specify path separator for i18n files (default: ".")
   --warn, -w                     print warnings (default: false)
   --help, -h                     show help
   --version, -v                  print the version

COMMAND generate
USAGE:
   polyglot generate [options]

OPTIONS:
   --in string, -i string   specify input file (default: "i18n.hcl")
   --out string, -o string  specify output directory (default: "./i18n")
   --force-default, -d      force i18n_<LANG> file generation even if <LANG> is the default language (default: false)   
   --help, -h               show help
   
COMMAND migrate
USAGE:
   polyglot migrate [options]

OPTIONS:
   --in string, -i string   specify input directory (default: "./i18n")
   --out string, -o string  specify output directory (default: "./i18n.hcl")
   --help, -h               show help

How do I try it out?

After pulling this repo and building the package (eg. with go build -o ./polyglot), try running polyglot on the provided example.hcl file with ./polyglot -w g -i example.hcl.

Are there more features coming?

Perhaps :)

About

i18n helper CLI tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published