Documentation

Localization extends PackageLocalization
in package

Package localization for `real-utils` package.

Table of Contents

Properties

$packageDir  : mixed
$packageInfo  : mixed
$remoteMeta  : mixed
$rootSlug  : 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.
getPackage()  : string
Get package name.
getPackageDir()  : string
Getter.
getParentLanguageFolder()  : mixed
Get the `/languages` folder which is directly located under the plugins path.
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`.
getRootSlug()  : string
Getter.
hooks()  : mixed
Add filters to WordPress runtime.
instance()  : PackageLocalization
New instance.
instanceThis()  : mixed
Create instance.
load_script_translation_file()  : mixed
Reuse JSON files from other plugins in the `mo-cache` folder.
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.
__construct()  : mixed
C'tor.
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.

Properties

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
see
https://github.com/WordPress/WordPress/blob/34dd52dea760b8a0e81860b010d9f5057fa3c38e/wp-includes/load.php#L617-L651

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

getPackageDir()

Getter.

public getPackageDir() : string
Tags
codeCoverageIgnore
Return values
string

getParentLanguageFolder()

Get the `/languages` folder which is directly located under the plugins path.

public static getParentLanguageFolder(string $path[, bool $appendFile = false ][, string $format = 'filesystem' ]) : mixed
Parameters
$path : string

A path to a folder or file within the plugins folder

$appendFile : bool = false

If true, it automatically appends the basename of the $path to the resulting path

$format : string = 'filesystem'

The result format, can be filesystem or url

getPotLanguages()

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

getRootSlug()

Getter.

public getRootSlug() : string
Tags
codeCoverageIgnore
Return values
string

hooks()

Add filters to WordPress runtime.

public hooks() : mixed

instanceThis()

Create instance.

public static instanceThis() : mixed
Tags
codeCoverageIgnore

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
see
https://app.clickup.com/t/2gfb42y?comment=90040016362143

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
see
https://core.trac.wordpress.org/ticket/32052
see
https://core.trac.wordpress.org/ticket/17268
see
https://app.clickup.com/t/861m3qqb7

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|string

getPackageInfo()

Get the directory where the languages folder exists.

protected abstract getPackageInfo(string $type) : array<string|int, string>

The returned string array should look like this: [0] = Full path to the "languages" folder [1] = Used textdomain [2]? = Use different prefix domain in filename

Parameters
$type : string
Return values
array<string|int, string>

        
On this page

Search results