Skip to main content

Easy to use abstractions for localizing your python apps.

Project description

# Localizator

Purpose of this simple package is to give easy to use abstractions for localizing your python app. Generally this package was made just for my telegram bots.

## Initialization
Firstly, you have to create localizator object:
```Python
from localizator import Localizator

localizator = Localizator()
```

Also, you could pass `LocalizationsProvider` and default language. LocalizationsProvider is fabric that creates `Localization`s objects by language name.
By default it will use YAML implementation that looks for `*.yaml` files inside `localizations` directory, but you could create your own localizations provider or at least change directory if it's necessary.

If you did not change anything in localizator initialization, create directory inside working directory called `localizations` and create file `en.yaml` with example content:
```yaml
foo: bar

extended_foo:
bar: foo

world: "{} world"
formatting: "Hello, {}!"
named_formatting: "Hello, {world}!"
```

## Simple use

After that you can start using localizator:

```Python
from localizator import LocalizationDescription
from localizator import Localizator

localizator = Localizator()

print(localizator.get_localization(LocalizationDescription(['foo'])))
print(localizator.get_localization(LocalizationDescription(['extended_foo', 'bar'])))
```

## Describer
Looks not really simple? Yeah, it's, but do not stop here! We have _brand new_ `Describer`. It allows to make your localization really simple, i mean, just look:

```Python
from localizator import LocalizationDescriber
from localizator import Localizator

d = LocalizationDescriber()
localizator = Localizator()

print(localizator.get_localization(d.foo))
print(localizator.get_localization(d.extended_foo.bar))

# And even more!
print(localizator.get_localization(d.formatting("world")))
print(localizator.get_localization(d.named_formatting(world="world")))


# Moar!
print(localizator.get_localization(d.formatting(d.world('breathtaking'))))
```

Also, if you want to highlight your paths to localizations as strings, you could use string:
```Python
print(localizator.get_localization(d('foo')))
print(localizator.get_localization(d('extended_foo.bar')))
```

Project details


Release history Release notifications

This version

0.1.0

Download files

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

Files for localizator, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size localizator-0.1.0.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page