I18n::get_i18n_url_strings_for_domains( TribeEventsarray $strings, TribeEventsarray $languages, TribeEventsarray $domains = array('default'), int $flags = 7 )
Get all possible translations for a URL String based on the given Languages and Domains.
Contents
WARNING: This function is slow because it deals with files, so don’t overuse it! Differently from the get_i18n_strings method this will not use any domain that’s not specified.
This function is same as above one, but instead of sanitizing with ‘sanitize_key()’ which removes ‘%’, it uses ‘sanitize_title()’.
Parameters
- $strings
-
(<span class="TribeEventsarray">TribeEventsarray) (Required) An array of strings (required).
- $languages
-
(<span class="TribeEventsarray">TribeEventsarray) (Required) Which l10n to fetch the string (required).
- $domains
-
(<span class="TribeEventsarray">TribeEventsarray) (Optional) Possible domains to re-load.
Default value: array('default')
- $flags
-
(int) (Optional) An integer resulting from the combination of compilation flags; defaults to
static::COMPILE_ALLto compile all versions of the translations.static::COMPILE_INPUTwill compile the translation for the string, as input.static::COMPILE_STRTOLOWERwill compile the translation for the string in its lowercase version.static::COMPILE_UCFIRSTwill compile the translation for the string in its title version.Default value: 7
Return
(TribeEventsarray<string,array|TribeEventsstring>) A multi level array with the possible translations for the given strings.
Source
File: src/Tribe/I18n.php
public function get_i18n_url_strings_for_domains( $strings, $languages, $domains = [ 'default' ], $flags = 7 ) {
sort( $languages );
$strings_buffer = [ $strings ];
foreach ( $languages as $language ) {
// Override the current locale w/ the one we need to compile the translations.
$language_strings = $this->with_locale(
$language,
[ $this, 'compile_translations' ],
[ $strings, $domains, $flags ]
);
$strings_buffer[] = $language_strings;
}
$strings = count( $strings_buffer ) > 1
? array_merge_recursive( ... $strings_buffer )
: reset( $strings_buffer );
// Prevent empty strings and duplicates.
foreach ( $strings as $key => $value ) {
$strings[ $key ] = array_filter(
array_unique(
array_map( 'sanitize_title', (array) $value )
)
);
}
return $strings;
}
Changelog
| Version | Description |
|---|---|
| 6.0.2 | Introduced. |