\MatthiasWeb\UtilsPackageLocalization

Base i18n management for backend and frontend for a package.

For non-utils packages you need to extend from this class and properly fill the constructor.

Summary

Methods
Properties
Constants
clearMoCacheDir()
getLanguageFromFile()
override_load_textdomain()
hooks()
getPotLanguages()
getMoCacheDir()
getRootSlug()
getPackage()
getPackageDir()
instance()
No public properties found
No constants found
getPackageInfo()
__construct()
No protected properties found
N/A
No private methods found
$rootSlug
$packageDir
$packageInfo
N/A

Properties

$rootSlug

$rootSlug :

Type

$packageDir

$packageDir :

Type

$packageInfo

$packageInfo :

Type

Methods

clearMoCacheDir()

clearMoCacheDir(string  $slug)

Clear the MO cache directory for a given plugin.

Parameters

string $slug

getLanguageFromFile()

getLanguageFromFile(string  $file)

Obtain language key from a file name.

Parameters

string $file

override_load_textdomain()

override_load_textdomain(boolean  $plugin_override,string  $domain,string  $mofile)

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.

Parameters

boolean $plugin_override
string $domain
string $mofile

hooks()

hooks()

Add filters to WordPress runtime.

getPotLanguages()

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.

getMoCacheDir()

getMoCacheDir(string  $slug)

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.

This function is expensive, so we cached it to $GLOBALS.

Parameters

string $slug

getRootSlug()

getRootSlug(): string

Getter.

Returns

string

getPackage()

getPackage(): string

Get package name.

Returns

string

getPackageDir()

getPackageDir(): string

Getter.

Returns

string

instance()

instance(string  $rootSlug,string  $packageDir): \MatthiasWeb\Utils\PackageLocalization

New instance.

Parameters

string $rootSlug
string $packageDir

Returns

\MatthiasWeb\Utils\PackageLocalization

getPackageInfo()

getPackageInfo(string  $type): array<mixed,string>

Get the directory where the languages folder exists.

Parameters

string $type

Returns

array<mixed,string>

__construct()

__construct(string  $rootSlug,string  $packageDir)

C'tor.

Parameters

string $rootSlug

Your workspace scope name.

string $packageDir

Absolute path to your package.