[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/ -> functions-l10n.php (summary)

YOURLS Translation API YOURLS modification of a small subset from WordPress' Translation API implementation. GPL License

File Size: 1129 lines (40 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

YOURLS_Locale_Formats:: (16 methods):
  init()
  get_weekday()
  get_weekday_initial()
  get_weekday_abbrev()
  get_month()
  get_month_abbrev()
  get_meridiem()
  register_globals()
  __construct()
  is_rtl()
  yourls_load_custom_textdomain()
  yourls_is_rtl()
  yourls_l10n_weekday_abbrev()
  yourls_l10n_weekday_initial()
  yourls_l10n_month_abbrev()
  yourls_l10n_months()

Defines 16 functions

  yourls_get_locale()
  yourls_translate()
  yourls_translate_with_context()
  yourls__()
  yourls_s()
  yourls_se()
  yourls_esc_attr__()
  yourls_esc_html__()
  yourls_e()
  yourls_esc_attr_e()
  yourls_esc_html_e()
  yourls_x()
  yourls_xe()
  yourls_esc_attr_x()
  yourls_esc_html_x()
  yourls_n()
  yourls_nx()
  yourls_n_noop()
  yourls_nx_noop()
  yourls_translate_nooped_plural()
  yourls_load_textdomain()
  yourls_unload_textdomain()
  yourls_load_default_textdomain()
  yourls_get_translations_for_domain()
  yourls_is_textdomain_loaded()
  yourls_translate_user_role()
  yourls_get_available_languages()
  yourls_number_format_i18n()
  yourls_date_i18n()

Class: YOURLS_Locale_Formats  - X-Ref

Class that loads the calendar locale.

init()   X-Ref
Sets up the translated strings and object properties.

The method creates the translatable strings for various
calendar elements. Which allows for specifying locale
specific calendar names and text direction.

return: void
since: 1.6

get_weekday( $weekday_number )   X-Ref
Retrieve the full translated weekday word.

Week starts on translated Sunday and can be fetched
by using 0 (zero). So the week starts with 0 (zero)
and ends on Saturday with is fetched by using 6 (six).

param: int|string $weekday_number 0 for Sunday through 6 Saturday
return: string Full translated weekday
since: 1.6

get_weekday_initial( $weekday_name )   X-Ref
Retrieve the translated weekday initial.

The weekday initial is retrieved by the translated
full weekday word. When translating the weekday initial
pay attention to make sure that the starting letter does
not conflict.

param: string $weekday_name
return: string
since: 1.6

get_weekday_abbrev( $weekday_name )   X-Ref
Retrieve the translated weekday abbreviation.

The weekday abbreviation is retrieved by the translated
full weekday word.

param: string $weekday_name Full translated weekday word
return: string Translated weekday abbreviation
since: 1.6

get_month( $month_number )   X-Ref
Retrieve the full translated month by month number.

The $month_number parameter has to be a string
because it must have the '0' in front of any number
that is less than 10. Starts from '01' and ends at
'12'.

You can use an integer instead and it will add the
'0' before the numbers less than 10 for you.

param: string|int $month_number '01' through '12'
return: string Translated full month name
since: 1.6

get_month_abbrev( $month_name )   X-Ref
Retrieve translated version of month abbreviation string.

The $month_name parameter is expected to be the translated or
translatable version of the month.

param: string $month_name Translated month to get abbreviated version
return: string Translated abbreviated month
since: 1.6

get_meridiem( $meridiem )   X-Ref
Retrieve translated version of meridiem string.

The $meridiem parameter is expected to not be translated.

param: string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version.
return: string Translated version
since: 1.6

register_globals()   X-Ref
Global variables are deprecated. For backwards compatibility only.

return: void
since: 1.6

__construct()   X-Ref
Constructor which calls helper methods to set up object variables

return: YOURLS_Locale_Formats
since: 1.6

is_rtl()   X-Ref
Checks if current locale is RTL.

return: bool Whether locale is RTL.
since: 1.6

yourls_load_custom_textdomain( $domain, $path )   X-Ref
Loads a custom translation file (for a plugin, a theme, a public interface...) if locale is defined

The .mo file should be named based on the domain with a dash, and then the locale exactly,
eg 'myplugin-pt_BR.mo'

param: string $domain Unique identifier (the "domain") for retrieving translated strings
param: string $path Full path to directory containing MO files.
return: mixed Returns nothing if locale undefined, otherwise return bool: true on success, false on failure
since: 1.6

yourls_is_rtl()   X-Ref
Checks if current locale is RTL. Stolen from WP.

return: bool Whether locale is RTL.
since: 1.6

yourls_l10n_weekday_abbrev( $weekday = '' )   X-Ref
Return translated weekday abbreviation (3 letters, eg 'Fri' for 'Friday')

The $weekday var can be a textual string ('Friday'), a integer (0 to 6) or an empty string
If $weekday is an empty string, the function returns an array of all translated weekday abbrev

param: mixed $weekday A full textual weekday, eg "Friday", or an integer (0 = Sunday, 1 = Monday, .. 6 = Saturday)
return: mixed Translated weekday abbreviation, eg "Ven" (abbrev of "Vendredi") for "Friday" or 5, or array of all weekday abbrev
since: 1.6

yourls_l10n_weekday_initial( $weekday = '' )   X-Ref
Return translated weekday initial (1 letter, eg 'F' for 'Friday')

The $weekday var can be a textual string ('Friday'), a integer (0 to 6) or an empty string
If $weekday is an empty string, the function returns an array of all translated weekday initials

param: mixed $weekday A full textual weekday, eg "Friday", an integer (0 = Sunday, 1 = Monday, .. 6 = Saturday) or empty string
return: mixed Translated weekday initial, eg "V" (initial of "Vendredi") for "Friday" or 5, or array of all weekday initials
since: 1.6

yourls_l10n_month_abbrev( $month = '' )   X-Ref
Return translated month abbrevation (3 letters, eg 'Nov' for 'November')

The $month var can be a textual string ('November'), a integer (1 to 12), a two digits strings ('01' to '12), or an empty string
If $month is an empty string, the function returns an array of all translated abbrev months ('January' => 'Jan', ...)

param: mixed $month Empty string, a full textual weekday, eg "November", or an integer (1 = January, .., 12 = December)
return: mixed Translated month abbrev (eg "Nov"), or array of all translated abbrev months
since: 1.6

yourls_l10n_months()   X-Ref
Return array of all translated months

return: array Array of all translated months
since: 1.6

Functions
Functions that are not part of a class:

yourls_get_locale()   X-Ref
Gets the current locale.

If the locale is set, then it will filter the locale in the 'get_locale' filter
hook and return the value.

If the locale is not set already, then the YOURLS_LANG constant is used if it is
defined. Then it is filtered through the 'get_locale' filter hook and the value
for the locale global set and the locale is returned.

The process to get the locale should only be done once, but the locale will
always be filtered using the 'get_locale' hook.

return: string The locale of the YOURLS instance
since: 1.6

yourls_translate( $text, $domain = 'default' )   X-Ref
Retrieves the translation of $text. If there is no translation, or
the domain isn't loaded, the original text is returned.

param: string $text Text to translate.
param: string $domain Domain to retrieve the translated text.
return: string Translated text
since: 1.6

yourls_translate_with_context( $text, $context, $domain = 'default' )   X-Ref
Retrieves the translation of $text with a given $context. If there is no translation, or
the domain isn't loaded, the original text is returned.

Quite a few times, there will be collisions with similar translatable text
found in more than two places but with different translated context.

By including the context in the pot file translators can translate the two
strings differently.

param: string $text Text to translate.
param: string $context Context.
param: string $domain Domain to retrieve the translated text.
return: string Translated text
since: 1.6

yourls__( $text, $domain = 'default' )   X-Ref
Retrieves the translation of $text. If there is no translation, or
the domain isn't loaded, the original text is returned.

param: string $text Text to translate
param: string $domain Optional. Domain to retrieve the translated text
return: string Translated text
since: 1.6

yourls_s( $pattern )   X-Ref
Return a translated sprintf() string (mix yourls__() and sprintf() in one func)

Instead of doing sprintf( yourls__( 'string %s' ), $arg ) you can simply use:
yourls_s( 'string %s', $arg )
This function accepts an arbitrary number of arguments:
- first one will be the string to translate, eg "hello %s my name is %s"
- following ones will be the sprintf arguments, eg "world" and "Ozh"
- if there are more arguments passed than needed, the last one will be used as the translation domain

param: mixed ...$pattern Text to translate, then $arg1: optional sprintf tokens, and $arg2: translation domain
return: string Translated text
since: 1.6

yourls_se( $pattern )   X-Ref
Echo a translated sprintf() string (mix yourls__() and sprintf() in one func)

Instead of doing printf( yourls__( 'string %s' ), $arg ) you can simply use:
yourls_se( 'string %s', $arg )
This function accepts an arbitrary number of arguments:
- first one will be the string to translate, eg "hello %s my name is %s"
- following ones will be the sprintf arguments, eg "world" and "Ozh"
- if there are more arguments passed than needed, the last one will be used as the translation domain

param: string ...$pattern Text to translate, then optional sprintf tokens, and optional translation domain
return: void Translated text
since: 1.6

yourls_esc_attr__( $text, $domain = 'default' )   X-Ref
Retrieves the translation of $text and escapes it for safe use in an attribute.
If there is no translation, or the domain isn't loaded, the original text is returned.

param: string $text Text to translate
param: string $domain Optional. Domain to retrieve the translated text
return: string Translated text
since: 1.6

yourls_esc_html__( $text, $domain = 'default' )   X-Ref
Retrieves the translation of $text and escapes it for safe use in HTML output.
If there is no translation, or the domain isn't loaded, the original text is returned.

param: string $text Text to translate
param: string $domain Optional. Domain to retrieve the translated text
return: string Translated text
since: 1.6

yourls_e( $text, $domain = 'default' )   X-Ref
Displays the returned translated text from yourls_translate().

param: string $text Text to translate
param: string $domain Optional. Domain to retrieve the translated text
return: void
since: 1.6

yourls_esc_attr_e( $text, $domain = 'default' )   X-Ref
Displays translated text that has been escaped for safe use in an attribute.

param: string $text Text to translate
param: string $domain Optional. Domain to retrieve the translated text
return: void
since: 1.6

yourls_esc_html_e( $text, $domain = 'default' )   X-Ref
Displays translated text that has been escaped for safe use in HTML output.

param: string $text Text to translate
param: string $domain Optional. Domain to retrieve the translated text
return: void
since: 1.6

yourls_x( $text, $context, $domain = 'default' )   X-Ref
Retrieve translated string with gettext context

Quite a few times, there will be collisions with similar translatable text
found in more than two places but with different translated context.

By including the context in the pot file translators can translate the two
strings differently.

param: string $text Text to translate
param: string $context Context information for the translators
param: string $domain Optional. Domain to retrieve the translated text
return: string Translated context string
since: 1.6

yourls_xe( $text, $context, $domain = 'default' )   X-Ref
Displays translated string with gettext context

param: string $text Text to translate
param: string $context Context information for the translators
param: string $domain Optional. Domain to retrieve the translated text
return: void Echoes translated context string
since: 1.7.1

yourls_esc_attr_x( $single, $context, $domain = 'default' )   X-Ref
Return translated text, with context, that has been escaped for safe use in an attribute

param: string   $single
param: string   $context
param: string   $domain Optional. Domain to retrieve the translated text
return: string
since: 1.6

yourls_esc_html_x( $single, $context, $domain = 'default' )   X-Ref
Return translated text, with context, that has been escaped for safe use in HTML output

param: string   $single
param: string   $context
param: string   $domain Optional. Domain to retrieve the translated text
return: string
since: 1.6

yourls_n( $single, $plural, $number, $domain = 'default' )   X-Ref
Retrieve the plural or single form based on the amount.

If the domain is not set in the $yourls_l10n list, then a comparison will be made
and either $plural or $single parameters returned.

If the domain does exist, then the parameters $single, $plural, and $number
will first be passed to the domain's ngettext method. Then it will be passed
to the 'translate_n' filter hook along with the same parameters. The expected
type will be a string.

param: string $single The text that will be used if $number is 1
param: string $plural The text that will be used if $number is not 1
param: int $number The number to compare against to use either $single or $plural
param: string $domain Optional. The domain identifier the text should be retrieved in
return: string Either $single or $plural translated text
since: 1.6

yourls_nx($single, $plural, $number, $context, $domain = 'default')   X-Ref
A hybrid of yourls_n() and yourls_x(). It supports contexts and plurals.

param: string $single   The text that will be used if $number is 1
param: string $plural   The text that will be used if $number is not 1
param: int $number      The number to compare against to use either $single or $plural
param: string $context  Context information for the translators
param: string $domain   Optional. The domain identifier the text should be retrieved in
return: string          Either $single or $plural translated text
since: 1.6

yourls_n_noop( $singular, $plural, $domain = null )   X-Ref
Register plural strings in POT file, but don't translate them.

Used when you want to keep structures with translatable plural strings and
use them later.

Example:
$messages = array(
'post' => yourls_n_noop('%s post', '%s posts'),
'page' => yourls_n_noop('%s pages', '%s pages')
);
...
$message = $messages[$type];
$usable_text = sprintf( yourls_translate_nooped_plural( $message, $count ), $count );

param: string $singular Single form to be i18ned
param: string $plural Plural form to be i18ned
param: string $domain Optional. The domain identifier the text will be retrieved in
return: array array($singular, $plural)
since: 1.6

yourls_nx_noop( $singular, $plural, $context, $domain = null )   X-Ref
Register plural strings with context in POT file, but don't translate them.

param: string $singular Single form to be i18ned
param: string $plural   Plural form to be i18ned
param: string $context  Context information for the translators
param: string $domain   Optional. The domain identifier the text will be retrieved in
return: array           array($singular, $plural)
since: 1.6

yourls_translate_nooped_plural( $nooped_plural, $count, $domain = 'default' )   X-Ref
Translate the result of yourls_n_noop() or yourls_nx_noop()

param: array $nooped_plural Array with singular, plural and context keys, usually the result of yourls_n_noop() or yourls_nx_noop()
param: int $count Number of objects
param: string $domain Optional. The domain identifier the text should be retrieved in. If $nooped_plural contains
return: string
since: 1.6

yourls_load_textdomain( $domain, $mofile )   X-Ref
Loads a MO file into the domain $domain.

If the domain already exists, the translations will be merged. If both
sets have the same string, the translation from the original value will be taken.

On success, the .mo file will be placed in the $yourls_l10n global by $domain
and will be a MO object.

param: string $domain Unique identifier for retrieving translated strings
param: string $mofile Path to the .mo file
return: bool True on success, false on failure
since: 1.6

yourls_unload_textdomain( $domain )   X-Ref
Unloads translations for a domain

param: string $domain Textdomain to be unloaded
return: bool Whether textdomain was unloaded
since: 1.6

yourls_load_default_textdomain()   X-Ref
Loads default translated strings based on locale.

Loads the .mo file in YOURLS_LANG_DIR constant path from YOURLS root. The
translated (.mo) file is named based on the locale.

return: bool True on success, false on failure
since: 1.6

yourls_get_translations_for_domain( $domain )   X-Ref
Returns the Translations instance for a domain. If there isn't one,
returns empty Translations instance.

param: string $domain
return: NOOPTranslations An NOOPTranslations translation instance

yourls_is_textdomain_loaded( $domain )   X-Ref
Whether there are translations for the domain

param: string $domain
return: bool Whether there are translations
since: 1.6

yourls_translate_user_role( $name )   X-Ref
Translates role name. Unused.

Unused function for the moment, we'll see when there are roles.
From the WP source: Since the role names are in the database and
not in the source there are dummy gettext calls to get them into the POT
file and this function properly translates them back.

param: string $name The role name
return: string Translated role name
since: 1.6

yourls_get_available_languages( $dir = null )   X-Ref
Get all available languages (*.mo files) in a given directory. The default directory is YOURLS_LANG_DIR.

param: string $dir A directory in which to search for language files. The default directory is YOURLS_LANG_DIR.
return: array Array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names.
since: 1.6

yourls_number_format_i18n( $number, $decimals = 0 )   X-Ref
Return integer number to format based on the locale.

param: int $number The number to convert based on locale.
param: int $decimals Precision of the number of decimal places.
return: string Converted number in string format.
since: 1.6

yourls_date_i18n( $dateformatstring, $timestamp = false )   X-Ref
Return the date in localized format, based on timestamp.

If the locale specifies the locale month and weekday, then the locale will
take over the format for the date. If it isn't, then the date format string
will be used instead.

param: string   $dateformatstring   Format to display the date.
param: bool|int $timestamp          Optional, Unix timestamp, default to current timestamp (with offset if applicable)
return: string                       The date, translated if locale specifies it.
since: 1.6



Generated: Wed Sep 18 05:10:18 2024 Cross-referenced by PHPXref 0.7.1