\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 + override 'override' method.

Summary

Methods
Properties
Constants
packageInfoParserForOverrides()
load_script_translation_file()
getLanguageFromFile()
override_load_textdomain()
hooks()
resolveSymlinks()
getPotLanguages()
getRootSlug()
getPackage()
getPackageDir()
instance()
$PACKAGE_INFO_FRONTEND
$PACKAGE_INFO_BACKEND
No constants found
override()
getPackageInfo()
__construct()
No protected properties found
N/A
No private methods found
$rootSlug
$packageDir
N/A

Properties

$PACKAGE_INFO_FRONTEND

$PACKAGE_INFO_FRONTEND :

Type

$PACKAGE_INFO_BACKEND

$PACKAGE_INFO_BACKEND :

Type

$rootSlug

$rootSlug :

Type

$packageDir

$packageDir :

Type

Methods

packageInfoParserForOverrides()

packageInfoParserForOverrides(string  $type,string  $resolve,string  $domain): array<mixed,string>

Common helper to get an array of variables for package info.

Parameters

string $type
string $resolve
string $domain

Returns

array<mixed,string>

load_script_translation_file()

load_script_translation_file(string  $file,string  $handle,string  $domain): string

Allow language overrides so for example de_AT uses de_DE to avoid duplicate

.po files and management. This is for JavaScript files!

Parameters

string $file
string $handle
string $domain

Returns

string

getLanguageFromFile()

getLanguageFromFile(string  $file)

Obtain language key from a file name.

Parameters

string $file

override_load_textdomain()

override_load_textdomain(boolean  $override,string  $domain,string  $mofile): boolean

Allow language overrides so for example de_AT uses de_DE to avoid duplicate

.po files and management. This is for backend PHP files!

Parameters

boolean $override
string $domain
string $mofile

Returns

boolean

hooks()

hooks()

Add filters to WordPress runtime.

resolveSymlinks()

resolveSymlinks(string  $path): string

Resolves symlinks for a given file.

Parameters

string $path

Returns

string

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.

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

override()

override(string  $locale): string

Put your language overrides here!

Parameters

string $locale

Returns

string

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.