|
| 1 | +# Bright Nucleus Localization |
| 2 | + |
| 3 | +[](https://packagist.org/packages/brightnucleus/localization) |
| 4 | +[](https://packagist.org/packages/brightnucleus/localization) |
| 5 | +[](https://packagist.org/packages/brightnucleus/localization) |
| 6 | +[](https://packagist.org/packages/brightnucleus/localization) |
| 7 | + |
| 8 | +WordPress localization for Bright Nucleus components. |
| 9 | + |
| 10 | +## Table Of Contents |
| 11 | + |
| 12 | +* [Installation](#installation) |
| 13 | +* [Basic Usage](#basic-usage) |
| 14 | +* [Filters](#filters) |
| 15 | +* [Contributing](#contributing) |
| 16 | +* [License](#license) |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +The best way to use this package is through Composer: |
| 21 | + |
| 22 | +```BASH |
| 23 | +composer require brightnucleus/localization |
| 24 | +``` |
| 25 | + |
| 26 | +## Basic Usage |
| 27 | + |
| 28 | +This package provides a trait to be used within Bright Nucleus components to load the translation files (compiled `*.mo`-files) for a given locale. |
| 29 | + |
| 30 | +To use the trait, import it into your class, and call the `loadLocalization( $domain, $path )` method. |
| 31 | + |
| 32 | +__Example:__ |
| 33 | + |
| 34 | +```PHP |
| 35 | +<?php namespace Localization\Example; |
| 36 | + |
| 37 | +use BrightNucleus\Localization\LocalizationTrait; |
| 38 | + |
| 39 | +class TranslatedClass { |
| 40 | + |
| 41 | + use LocalizationTrait; |
| 42 | + |
| 43 | + public function register() { |
| 44 | + |
| 45 | + $this->loadLocalization( |
| 46 | + 'bn-localization-example', |
| 47 | + __DIR__ . '/../languages' |
| 48 | + ); |
| 49 | + |
| 50 | + // Your normal registration comes here, knowing that all `gettext` |
| 51 | + // strings have already been translated. |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## Filters |
| 57 | + |
| 58 | +Each loading of localization files passes through two filters: |
| 59 | + |
| 60 | +1. __`Localization::LOCALE_FILTER`__ - Filter the locale of a Bright Nucleus library. |
| 61 | + |
| 62 | + Arguments: |
| 63 | + * `$locale` (string) - The plugin's current locale. |
| 64 | + * `$domain` (string) - Text domain. Unique identifier for retrieving translated strings. |
| 65 | + |
| 66 | + Return value: |
| 67 | + * `$locale` (string) - Filtered locale. |
| 68 | + |
| 69 | +2. __`Localization::MOFILE_FILTER`__ - Filter the name of the MO-file of a Bright Nucleus library. |
| 70 | + |
| 71 | + Arguments: |
| 72 | + * `$path` (string) - Path to the MO-file. |
| 73 | + * `$locale` (string) - The plugin's current locale. |
| 74 | + * `$domain` (string) - Text domain. Unique identifier for retrieving translated strings. |
| 75 | + |
| 76 | + Return value: |
| 77 | + * `$path` (string) - Fitlered path to the MO-file. |
| 78 | + |
| 79 | +## Contributing |
| 80 | + |
| 81 | +All feedback / bug reports / pull requests are welcome. |
| 82 | + |
| 83 | +## License |
| 84 | + |
| 85 | +Copyright (c) 2016 Alain Schlesser, Bright Nucleus |
| 86 | + |
| 87 | +This code is licensed under the [MIT License](LICENSE). |
0 commit comments