/nerdz-translator

Easy and automated localizations for everyone.

Primary LanguagePerlMozilla Public License 2.0MPL-2.0

nerdz-translator

ultimate all-in-one translator for NERDZ strings

This program quickly translates a string in multiple languages, making localization a process much more easier and fun. There are lots of options which are thoughtfully documented in this manual.

Setting up the script

Before using this script you need to configure it in the source file.

Please open the main source file (nerdz_translator.pl) and start reading at line 18. Don't worry, you don't need any Perl knowledge.

Usage

nerdz-translator [options] [-k key] [string_to_translate]

Options:
  -i                   The input language.
  -o                   Comma-separated list of output languages.
  -k                   A key which represents the string you are translating.
  -l                   Shows a list of available languages, then exits.
  -O                   Enables direct output mode.
  -f                   The JSON file which will be edited if directout is on.
  -v                   Version information.
  -h                   This short help text.
  --manual             The full help text. Also available with perldoc.
  --output-format      The format string used as the output for each language
  --output-file-format Used to determine the path of the language files.
  --set-translation    Manually sets translations of different languages.

Available options

  • --translate-from, -i language

    Specifies the input language. The default is 'en'.

  • --translate-to, -o language-1,language-2,...

    Comma-separated list of output languages. The default is 'de', 'hr', 'en', 'pt', 'ro'.

  • --key, -k KEY

    A key which represents the string you are translating in a short form. Like ERR_DUMB_USER.

    This parameter is required.

  • --output-format format-string

    The format string used as the output for each language. Not used when --output-dir, -o is specified.

    Available variables:

    • =translated

      The translated string.

    • =qtranslated

      The translated string with quotes.

    • =to

      The language the string is being translated into.

    • =key

      The key specified with --key, -k.

    • =n

      A newline.

    Default: =to=n"=key": =qtranslated

    Which produces an output like:

      language_name
      "key": "value"
    
  • --output-file-format format-string

    The format string used to determine the final path of the language files. This is used only if --output-dir, -o is specified.

    Available variables:

    • =outdir

      The value of --output-dir, -o.

    • =outfn

      The value of --output-file, -f (or the default value).

    • =lang

      The language the string is being translated into.

    Default: =outdir/=lang/json/=outfn

  • -l

    Shows a list of available languages. Exits immediately afterwards.

  • --output-dir, -O directory

    Enables the file output mode. It reads the JSON files with the names specified in the --output-file, -f option (or the default value) and appends the traditional JSON "key": "value" mapping.

    NOTE: The JSON files are read and written by the Perl's JSON module. This means that your indentation, comments or any custom stuff which is not pure JSON will probably be deleted. However, the parser outputs a pretty 4-spaces indented JSON which should be nice to read.

  • --output-file, -f file

    The JSON file which will be edited if --output-dir, -O is specified. The final path of the JSON files will be determined by the value of --output-file-format. The default value is default.json.

  • --set-translation language-name translation

    This option manually sets the translation for language-name to translation. It is recommended to specify the translation parameter with the quotes, and it is mandatory if your translation contains spaces.

    This parameter is useful when you need the translation of your native language too. Let's say that I'm an Italian native-speaker and I'm translating in three different languages. Here's a command line which handles Italian too without automatic translation:

      nt -i en -o ro,hr,jp -k SOMETHING --set-translation it "Sì" Yes
    
  • --version, -v

    Shows the version of this program, Perl and Getopt.

  • --help, -h

    The short version of this manual.

  • --manual

    The full version of this manual.

Examples

All the examples assume nt as the executable file nerdz-translator.pl.

  • Basic translation with NO_THANKS as the key

      nt -k "NO_THANKS" "No thanks"
    
  • Changing the source language

      nt -i it -k "NO_THANKS" "No grazie"
    
  • Changing the target languages

      nt -i it -o en,ro -k "NO_THANKS" "No grazie"
    
  • Changing the output format

      nt -i it -o en,ro -k "NO_THANKS" --output-format "=translated=n" "No grazie"
    
  • Outputting to JSON files

      nt -i it -o en,ro -k "NO_THANKS" -O "path/to/langs" "No grazie"
    
  • Outputting to JSON files named tst.json

      nt -i it -o en,ro -k "NO_THANKS" -O "path/to/langs" -f "tst.json" "No grazie"
    
  • Setting the translation for English

      nt -i it -o ro -k "YES" --set-translation en "Yes" "Si"
    
  • Changing the output file format

      nt -k "YES" -O "some/path" --output-file-format "=outdir/=lang/=outfn" "Yes"
    
  • Showing the available languages from Bing

      nt -l
    

TODO

  • Use a JSON file for the configuration?

Author

Roberto Frenna <robertof.public@gmail.com>

Copyright and license

Copyright 2014 Roberto Frenna

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.