The Locale class

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

Einführung

A "Locale" is an identifier used to get language, culture, or regionally-specific behavior from an API. PHP locales are organized and identified the same way that the CLDR locales used by ICU (and many vendors of Unix-like operating systems, the Mac, Java, and so forth) use. Locales are identified using RFC 4646 language tags (which use hyphen, not underscore) in addition to the more traditional underscore-using identifiers. Unless otherwise noted the functions in this class are tolerant of both formats.

Examples of identifiers include:

  • en-US (English, United States)
  • zh-Hant-TW (Chinese, Traditional Script, Taiwan)
  • fr-CA, fr-FR (French for Canada and France respectively)

The Locale class (and related procedural functions) are used to interact with locale identifiers--to verify that an ID is well-formed, valid, etc. The extensions used by CLDR in UAX #35 (and inherited by ICU) are valid and used wherever they would be in ICU normally.

Locales cannot be instantiated as objects. All of the functions/methods provided are static.

The null or empty string obtains the "root" locale. The "root" locale is equivalent to "en_US_POSIX" in CLDR. Language tags (and thus locale identifiers) are case insensitive. There exists a canonicalization function to make case match the specification.

Klassenbeschreibung

class Locale {
/* Methoden */
public static acceptFromHttp(string $header): string|false
public static canonicalize(string $locale): ?string
public static composeLocale(array $subtags): string|false
public static filterMatches(string $languageTag, string $locale, bool $canonicalize = false): ?bool
public static getAllVariants(string $locale): ?array
public static getDefault(): string
public static getDisplayLanguage(string $locale, ?string $displayLocale = null): string|false
public static getDisplayName(string $locale, ?string $displayLocale = null): string|false
public static getDisplayRegion(string $locale, ?string $displayLocale = null): string|false
public static getDisplayScript(string $locale, ?string $displayLocale = null): string|false
public static getDisplayVariant(string $locale, ?string $displayLocale = null): string|false
public static getKeywords(string $locale): array|false|null
public static getPrimaryLanguage(string $locale): ?string
public static getRegion(string $locale): ?string
public static getScript(string $locale): ?string
public static lookup(
    array $languageTag,
    string $locale,
    bool $canonicalize = false,
    ?string $defaultLocale = null
): ?string
public static parseLocale(string $locale): ?array
public static setDefault(string $locale): bool
}

Vordefinierte Konstanten

Locale::DEFAULT_LOCALE (null)
Used as locale parameter with the methods of the various locale affected classes, such as NumberFormatter. This constant would make the methods to use default locale.

These constants describe the choice of the locale for the getLocale method of different classes.

Locale::ACTUAL_LOCALE (string)
This is locale the data actually comes from.
Locale::VALID_LOCALE (string)
This is the most specific locale supported by ICU.

These constants define how the Locales are parsed or composed. They should be used as keys in the argument array to locale_compose() and are returned from locale_parse() as keys of the returned associative array.

Locale::LANG_TAG (string)
Language subtag
Locale::EXTLANG_TAG (string)
Extended language subtag
Locale::SCRIPT_TAG (string)
Script subtag
Locale::REGION_TAG (string)
Region subtag
Locale::VARIANT_TAG (string)
Variant subtag
Locale::GRANDFATHERED_LANG_TAG (string)
Grandfathered Language subtag
Locale::PRIVATE_TAG (string)
Private subtag

Inhaltsverzeichnis

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Neuigkeiten für PHP-Entwickler: Laravel 11 Veröffentlichung

Am 12. März 2024 wurde die lang erwartete Version 11 des Laravel-Frameworks veröffentlicht, die eine Reihe von spannenden Neuerungen und Verbesserungen für die PHP-Entwicklungsgemeinschaft mit sich bringt. ...

Mike94

Autor : Mike94
Kategorie: PHP Magazin

Technisches SEO bleibt relevant

Technisches SEO – Was ist das überhaupt? Technisches SEO bezieht sich auf die Optimierung der technischen Aspekte deiner Webseite. Das Ziel ist klar! ...

admin

Autor : admin
Kategorie: SEO & Online-Marketing

Was ist neu in der PHP 8.2.10

PHP 8.2.10 ist eine der neuesten Versionen von PHP, die eine Reihe von Verbesserungen und neuen Funktionen mit sich bringt. In diesem Artikel werden wir einige der herausragenden Neuerungen und Verbesserungen dieser Version diskutieren. ...

admin

Autor : admin
Kategorie: Software-Updates

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Seltsames Verhalten von execute() oder Fehler meinerseits

Hallo liebe Community, ich habe ein kleines Problem und vielleicht kann mir ja jemand helfen, würde ich mich sehr drüber freuen. Unten steht e ...

Geschrieben von garibaldiwz am 22.03.2024 13:03:12
Forum: SQL / Datenbanken
Google reCAPTCHA in Kontaktformular einbinden

Überprüfen Sie den E-Mail-Versand: Stellen Sie sicher, dass die E-Mail-Funktion mail() ordnungsgemäß funktioniert und dass keine Fehler beim V ...

Geschrieben von Gast am 18.03.2024 04:54:16
Forum: PHP Developer Forum
`count.php`

Hallo cober93327, und Danke fuer deine Antwort! :-) Naja, so einen "Besucherzähler" auf der Webseite anzuzeigen ist schon eher etwas, das man a ...

Geschrieben von kekse1 am 17.03.2024 15:56:38
Forum: Projekthilfe
`count.php`

Es gibt dazu natuerlich auch eine recht ausfuehrliche Dokumentation in meinem GitHub-Repository Es würde meiner Ansicht nach enorm helfen, wenn D ...

Geschrieben von cober93327 am 14.03.2024 15:49:28
Forum: Projekthilfe