Localization
in package
Uses
UtilsProvider, Localization
i18n management for backend and frontend.
Table of Contents
Constants
- COMMON_SKIP_KEYS = ['slug']
- Keys of array which should be not translated with `translateArray`.
Properties
- $remoteMeta : mixed
Methods
- admin_notices() : mixed
- Show an admin notice about failed downloads of remote language packs.
- clearMoCacheDir() : mixed
- Clear the MO cache directory for a given plugin.
- enableAssetsDotDevowlIoLanguagePacksDownload() : mixed
- Enables the download of assets.devowl.io language packs endpoints.
- enableWordPressDotOrgLanguagePacksDownload() : mixed
- Enables the download of wordpress.org language packs endpoints.
- getDownloadLanguagePackError() : mixed
- Get the last error which happened during download of a given mofile.
- getLanguageFromFile() : mixed
- Obtain language key from a file name.
- getMoCacheDir() : mixed
- Get the cache directory for cached MO files after parsing. It also checks, if the directory is writable and create the path for a given plugin slug.
- getMofilePath() : mixed
- Get the path to the MO file within our plugin, the `wp-content/languages/plugins` or `wp-content/languages/mo-cache` folder.
- getPluginConstantPrefix() : string
- Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
- getPotLanguages() : mixed
- Get the languages which are available in the POT file. Why multiple? Imagine you want to use the pot file for `en_US` and `en_GB`. This can be useful for the `@devowl-wp/multilingual` package, especially the `TemporaryTextDomain` feature.
- getRemoteMeta() : array<string|int, mixed>|false
- Get the remote metadata saved in `languages/meta.json`.
- hooks() : mixed
- Add filters to WordPress runtime.
- load_script_translation_file() : mixed
- Reuse JSON files from other plugins in the `mo-cache` folder.
- multilingual() : mixed
- Make our plugin multilingual with the help of `AbstractSyncPlugin` and `Sync`! Also have a look at `BannerCustomize`, there are `LanguageDependingOption`'s.
- override_load_textdomain() : mixed
- Cache the results of the `MO` parser in a file in `wp-content/languages/mo-cache` because it is extremely slow on some WordPress installations.
- downloadLanguagePackForMofile() : WP_Error|false|string
- Try to download language pack from a remote server for a given language when our build of the plugin does not hold the translations.
- getPackageInfo() : array<string|int, string>
- Get the directory where the languages folder exists.
Constants
COMMON_SKIP_KEYS
Keys of array which should be not translated with `translateArray`.
public
mixed
COMMON_SKIP_KEYS
= ['slug']
Properties
$remoteMeta
private
mixed
$remoteMeta
= null
Methods
admin_notices()
Show an admin notice about failed downloads of remote language packs.
public
admin_notices() : mixed
clearMoCacheDir()
Clear the MO cache directory for a given plugin.
public
clearMoCacheDir(string $slug, string $domain) : mixed
Parameters
- $slug : string
- $domain : string
enableAssetsDotDevowlIoLanguagePacksDownload()
Enables the download of assets.devowl.io language packs endpoints.
public
static enableAssetsDotDevowlIoLanguagePacksDownload(string $slug) : mixed
Parameters
- $slug : string
enableWordPressDotOrgLanguagePacksDownload()
Enables the download of wordpress.org language packs endpoints.
public
static enableWordPressDotOrgLanguagePacksDownload(string $slug, string $dotOrgSlug) : mixed
Parameters
- $slug : string
- $dotOrgSlug : string
getDownloadLanguagePackError()
Get the last error which happened during download of a given mofile.
public
getDownloadLanguagePackError(string $slug, string $domain) : mixed
The scheme for the ExpireOption
matches [code => string, message => string]
.
Parameters
- $slug : string
- $domain : string
getLanguageFromFile()
Obtain language key from a file name.
public
getLanguageFromFile(string $file) : mixed
Parameters
- $file : string
getMoCacheDir()
Get the cache directory for cached MO files after parsing. It also checks, if the directory is writable and create the path for a given plugin slug.
public
static getMoCacheDir([string $slug = '' ]) : mixed
This function is expensive, so we cached it to $GLOBALS
.
The returned path can be either wp-content/languages/...
or wp-includes/languages/...
.
Parameters
- $slug : string = ''
Tags
getMofilePath()
Get the path to the MO file within our plugin, the `wp-content/languages/plugins` or `wp-content/languages/mo-cache` folder.
public
getMofilePath(string $mofile, string $domain) : mixed
Additionally, it returns the plugin slug which is associated to the passed mofile path.
Parameters
- $mofile : string
- $domain : string
getPluginConstantPrefix()
Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
public
getPluginConstantPrefix() : string
Tags
Return values
stringgetPotLanguages()
Get the languages which are available in the POT file. Why multiple? Imagine you want to use the pot file for `en_US` and `en_GB`. This can be useful for the `@devowl-wp/multilingual` package, especially the `TemporaryTextDomain` feature.
public
getPotLanguages() : mixed
getRemoteMeta()
Get the remote metadata saved in `languages/meta.json`.
public
getRemoteMeta() : array<string|int, mixed>|false
Return values
array<string|int, mixed>|false —false
when meta file cannot be read
hooks()
Add filters to WordPress runtime.
public
hooks() : mixed
load_script_translation_file()
Reuse JSON files from other plugins in the `mo-cache` folder.
public
load_script_translation_file(string $file, string $handle, string $domain) : mixed
Why? The download of remote files is currently only triggered for PHP textdomains, but not JSON translations.
That means, Real Media Library "requests" the devowl-wp-real-product-manager-wp-client
textdomain and downloads
it to mo-cache/real-media-library
, so no translations (in this case fr_FR
) are downloaded for real-physical-media
.
But, in WordPress, frontend packages are not loaded "isolated" and per plugin, they get loaded for the last enqueued plugin.
Parameters
- $file : string
- $handle : string
- $domain : string
Tags
multilingual()
Make our plugin multilingual with the help of `AbstractSyncPlugin` and `Sync`! Also have a look at `BannerCustomize`, there are `LanguageDependingOption`'s.
public
static multilingual() : mixed
override_load_textdomain()
Cache the results of the `MO` parser in a file in `wp-content/languages/mo-cache` because it is extremely slow on some WordPress installations.
public
override_load_textdomain(bool $plugin_override, string $domain, string $mofile) : mixed
Parameters
- $plugin_override : bool
- $domain : string
- $mofile : string
Tags
downloadLanguagePackForMofile()
Try to download language pack from a remote server for a given language when our build of the plugin does not hold the translations.
protected
downloadLanguagePackForMofile(string $mofile, string $slug, string $domain, string $locale) : WP_Error|false|string
Parameters
- $mofile : string
- $slug : string
- $domain : string
- $locale : string
Return values
WP_Error|false|stringgetPackageInfo()
Get the directory where the languages folder exists.
protected
getPackageInfo(string $type) : array<string|int, string>
Parameters
- $type : string