GithubHelp home page GithubHelp logo

i18nki's Introduction

i18nki

An easy to use localization file generator. i18nki parses localization keys from source files, then compiles them to a chosen localization format.

Install

Local envirornment installation with pipsi

git clone https://github.com/stillwwater/i18nki
cd i18nki
pipsi install .

Usage

python3 -m i18nki [-h] -i INPUT -o OUTPUT -f FILTER -c COMMENT [--compiler COMPILER]
Option Shortcut Description Example
--help -h Display help doc python3 i18nki.py -h
--input -i Specify an input directory (files to parse) -i /path/to/source/
--output -o Output file for compiled content -o en-US.po
--filter -f Regex string to match function calls in source file -f ".*?_\((.*?)\).*?$" matches _("my-string", arg);
--comment -c Specifies the comment string of the source language -c "//"
--compiler Specifies which compiler to use for the output file --compiler ini (see 'compilers' for more)
--separator Specifies key/value separator character --separator ' = '

Compilers

  • ini (default)
  • gettext or po

Example

python3 -m i18nki -i ./src -o pt-BR.ini -f ".*?Strings\.Load\((.*?)\).*?$" -c "//"

src/Program.cs

// Print welcome message
Console.WriteLine(Strings.Load("welcome-msg", name));
Console.WriteLine(Strings.Load("exit-msg"));
exitMsg = Strings.Load("exit-msg");

pt-BR.ini

[meta]
...
[strings]
; Print welcome message
; +param+ {0}: name
; @Program.cs:2
welcome-msg=

; @Program.cs:3 @Program.cs:4
exit-msg=

Custom Localization Formats

To use a custom localization format, create an object that inherits from Compiler (compiler.py) and override the compile_node(self, node: Node) function. The Node object has data parsed from the source files, including: key:str, args:list, comments:str, file:list, line:list.

Example using the Gettext compiler:

compilers/gettext.py

from i18nki.compiler import Compiler

class Gettext(Compiler):
    def __init__(self):
        self.header = '# SOME DESCRIPTIVE TITLE'
        self.name = 'Gettext'

    def compile_node(self, node):
        # example output of Gettext.compile_node:
        # #, Print welcome message
        # #, param+ {0}: name
        # #: @Program.cs:2
        # msid: "welcome"
        # msgstr:

        # the compile_comments function adds comments before each key
        # with the key's parameters, location in the source and other comments
        out = '\n' + self.compile_comments(node, comment_char='#,', alt_comment_char='#:')

        # compile key
        out += 'msgid: "%s"\nmsgstr:\n' % node.key
        return out

A option for this compiler is then added to __main__.py:

from i18nki.compilers import gettext

...

if compiler_choice == 'gettext' or compiler_choice == 'po':
    # change compiler option
    compiler = gettext.Gettext()

i18nki's People

Contributors

stillwwater avatar

Watchers

James Cloos avatar  avatar

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.