Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| I18nService | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| load_php_translations | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| load_js_translations | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Onboarding\Services; |
| 4 | |
| 5 | /** |
| 6 | * Class for handling internationalization. |
| 7 | */ |
| 8 | class I18nService { |
| 9 | |
| 10 | /** |
| 11 | * Loads the PHP translations from .mo files in the languages dir. |
| 12 | * The .mo file must be named $domain-$locale.mo |
| 13 | * |
| 14 | * @param [string] $domain The text domain. |
| 15 | * @param [string] $languages_dir The directory containing the .mo files. |
| 16 | * @return boolean |
| 17 | */ |
| 18 | public static function load_php_translations( $domain, $languages_dir ) { |
| 19 | return load_plugin_textdomain( |
| 20 | $domain, |
| 21 | false, |
| 22 | $languages_dir |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Localizes a particular script using a JSON file present in the languages dir. |
| 28 | * The JSON file must be named $domain-$locale-$script_slug.json. |
| 29 | * Note: The script must be registered before this function is called. |
| 30 | * |
| 31 | * @param [string] $domain The text domain. |
| 32 | * @param [string] $script_slug The slug of the registered script. |
| 33 | * @param [string] $languages_dir The directory containing the .json file for the script. |
| 34 | * @return boolean |
| 35 | */ |
| 36 | public static function load_js_translations( $domain, $script_slug, $languages_dir ) { |
| 37 | return wp_set_script_translations( |
| 38 | $script_slug, |
| 39 | $domain, |
| 40 | $languages_dir |
| 41 | ); |
| 42 | } |
| 43 | } |