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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file python-lang-1.0.0.tar.gz.

File metadata

  • Download URL: python-lang-1.0.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.6

File hashes

Hashes for python-lang-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1431d26abfa05b49d32c097e275f6be370e7490386d3c650870f0cbcd4381f40
MD5 5f36b0f451d63f364143840396cb69df
BLAKE2b-256 32c1e8fabcb83a7c57feeb8a78d9c45598e6937502867f987274a92ecc1669e9

See more details on using hashes here.

File details

Details for the file python_lang-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_lang-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.6

File hashes

Hashes for python_lang-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb9723b2fd6a1e67952664434d3abd40206907d6919744df445da9fd990e187
MD5 7c104d2f406a8318505673ccf1123081
BLAKE2b-256 8dc3868584278b5264cd318c3d20d65c0210796680278a3cd7c3ee9b31dce904

See more details on using hashes here.

Supported by

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