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


Download files

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

Source Distribution

localizator-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file localizator-0.1.0.tar.gz.

File metadata

  • Download URL: localizator-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.5

File hashes

Hashes for localizator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 91d8eef0ce275155f29b7865ddb3f1565601d0de0e3bc6ab1ca0da7b1f907272
MD5 540e54b01273488e9f076b89643f413d
BLAKE2b-256 d63815144b765dc7e68537180598f2f453afe9342a584847a8d8f6c43f1ff9b6

See more details on using hashes here.

Supported by

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