VuFind API Documentation

ExtendedIniNormalizer
in package
Uses TranslatorAwareTrait

Class to consistently format ExtendedIni language files.

Tags
category

VuFind

author

Demian Katz demian.katz@villanova.edu

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Main Site

Table of Contents

$reservedWords  : array<string|int, string>
Reserved words that need to be quoted when used as keys.
$translator  : TranslatorInterface
Translator
extractComments()  : string
Extract comments from an array of lines read from a file.
formatAsString()  : string
Normalize a TextDomain or array to a string that can be written to file.
getTranslator()  : TranslatorInterface
Get translator object.
getTranslatorLocale()  : string
Get the locale from the translator.
loadFileIntoArray()  : array<string|int, mixed>
Load a language file into an array of lines, stripping UTF-8 BOM if necessary.
normalizeArray()  : string
Normalize an array of lines from a file and return the result as a string.
normalizeDirectory()  : void
Normalize a directory on disk.
normalizeFile()  : void
Normalize a file on disk.
normalizeFileToString()  : string
Normalize a file from disk and returns the result as a string.
setTranslator()  : TranslatorAwareInterface
Set a translator
translate()  : string
Translate a string (or string-castable object)
translateWithPrefix()  : string
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
checkFileFormat()  : void
Check that the file to process is a valid language file.
extractTextDomain()  : array<string|int, mixed>
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
filenameMatchesFilter()  : bool
Check if the given filename matches the filter pattern
getDebugTranslation()  : string
Build a debug-mode translation
sanitizeTranslationKey()  : string
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
translateString()  : string
Get translation for a string

Properties

$reservedWords

Reserved words that need to be quoted when used as keys.

protected array<string|int, string> $reservedWords = ['yes']

Methods

extractComments()

Extract comments from an array of lines read from a file.

public extractComments(array<string|int, mixed> $contents) : string
Parameters
$contents : array<string|int, mixed>

Contents to scan for comments.

Return values
string

formatAsString()

Normalize a TextDomain or array to a string that can be written to file.

public formatAsString(array<string|int, mixed>|TextDomain $rawInput) : string
Parameters
$rawInput : array<string|int, mixed>|TextDomain

Language values to format.

Return values
string

getTranslator()

Get translator object.

public getTranslator() : TranslatorInterface
Return values
TranslatorInterface

getTranslatorLocale()

Get the locale from the translator.

public getTranslatorLocale([string $default = 'en' ]) : string
Parameters
$default : string = 'en'

Default to use if translator absent.

Return values
string

loadFileIntoArray()

Load a language file into an array of lines, stripping UTF-8 BOM if necessary.

public loadFileIntoArray(string $filename) : array<string|int, mixed>
Parameters
$filename : string

File to load

Return values
array<string|int, mixed>

normalizeArray()

Normalize an array of lines from a file and return the result as a string.

public normalizeArray(array<string|int, string> $fileArray) : string
Parameters
$fileArray : array<string|int, string>

Array of lines to normalize

Return values
string

normalizeDirectory()

Normalize a directory on disk.

public normalizeDirectory(string $dir, string $filter) : void
Parameters
$dir : string

Directory to normalize.

$filter : string

File name filter.

Return values
void

normalizeFile()

Normalize a file on disk.

public normalizeFile(string $file) : void
Parameters
$file : string

Filename.

Return values
void

normalizeFileToString()

Normalize a file from disk and returns the result as a string.

public normalizeFileToString(string $file) : string
Parameters
$file : string

Filename.

Return values
string

translate()

Translate a string (or string-castable object)

public translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

translateWithPrefix()

Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.

public translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$prefix : string

Translation key prefix

$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

checkFileFormat()

Check that the file to process is a valid language file.

protected checkFileFormat(array<string|int, mixed> $lines, string $filename) : void

Throws an exception if unexpected content is detected.

Parameters
$lines : array<string|int, mixed>

File contents

$filename : string

Filename

Tags
throws
Exception
Return values
void

extractTextDomain()

Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.

protected extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

Return values
array<string|int, mixed>

filenameMatchesFilter()

Check if the given filename matches the filter pattern

protected filenameMatchesFilter(string $filename, string $filter) : bool
Parameters
$filename : string

Filename

$filter : string

Filter

Return values
bool

getDebugTranslation()

Build a debug-mode translation

protected getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
$domain : string

Text domain

$str : string

String to translate

$tokens : array<string|int, mixed>

Tokens to inject into the translated string

Return values
string

sanitizeTranslationKey()

Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.

protected sanitizeTranslationKey(string $key) : string
Parameters
$key : string

Key to sanitize

Return values
string

Sanitized key

translateString()

Get translation for a string

protected translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
$rawStr : string

String to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$domain : string = 'default'

Text domain (omit for default)

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

Return values
string

Search results