Skip to main content

A simple library for building multilingual applications in Python

Project description

python-lang

A simple library for building multilingual applications in Python

Installation

Using pip

pip install python-lang

From the source

  • Clone the repo git clone https://github.com/Programista3/python-lang.git
  • Run python setup.py install

Usage

.py file

Add pyLang to your project

import python_lang as lang
_ = lang.get

Add language files (you can specify the language symbol as the second parameter)

lang.add("C:/project/locales/de.xml")
lang.add("C:/project/locales/pl.xml", "pl")

Select language for translation

lang.select('pl')

You can turn off the translation using

lang.select()

Use _() function to translate text

print(_("Hello World"))

You can view the list of added languages using

lang.all()

XML file

Use following template:

<?xml version="1.0" encoding="UTF-8"?>
<language code="language symbol">
  <translation text="first original text">first translated text</translation>
  <translation text="second original text">second translated text</translation>
  ...
</language>

Documentation

Functions

lang.add(path, code=None)
  Adds path and language code to the list of languages.
  Returns True if the language has been added successfully.

lang.all()
  Returns the list of added languages

lang.get(text)
  Returns translated text (if not found translation or language is not selected returns original text)

lang.select(lang=None)
  Selects the language used to translation.
  Returns True if the language has been selected successfully.

Variables

lang.file
  Contains the parsed file of the currently selected language

lang.langs
  Contains the list of added languages with their file paths

lang.selected
  Contains the code of the currently selected language

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-lang-1.0.0.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

python_lang-1.0.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page