aboutsummaryrefslogtreecommitdiffstats
path: root/includes/language/LanguageCode.php
Commit message (Collapse)AuthorAgeFilesLines
* Add @phpcs-require-sorted-array to language code arraysFomafix2025-02-111-0/+1
| | | | Change-Id: I883d128034fa8c8d6d6338358eeedc6b7c5f3df9
* Language: Mark constructor of LanguageCode unstable for nowAmir Sarabadani2024-10-221-1/+1
| | | | | | | | Since the branch cut is now, let's make this unstable for now and then change it once we are confident it'll be stable. Bug: T376565 Change-Id: Id7dd735abc5a97a0dfbd50484a8ae989b6c1738f
* Language: Introduce getContentLanguageCode() serviceAmir Sarabadani2024-10-161-0/+20
| | | | | | | | | | | | | | | And use that as much as possible. This makes bootstraping services much faster since Language object is extremely heavy (specially to initialize) and that's why in LanguageFactory it's behind a cache (see LanguageFactory::getRawLanguage) At the same time, most uses of Language object only need the language code (after normalization and mapping and validation) and this allows such change to happen fast and way more decoupled from Language object that has more than 100 methods. Bug: T376565 Change-Id: I1c3d94454896842939dfaad8cbf742e5a3ae5438
* Move Language and friends into Language namespaceJames D. Forrester2024-08-101-0/+5
| | | | | Bug: T353458 Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
* [doc] Update filename in LanguageCode::getDeprecatedCodeMapping() commentC. Scott Ananian2024-04-111-3/+4
| | | | | Followup-To: 7fe63e48c5e61525b8935006bf1a6b442dc2d0d8 Change-Id: I2de451c07451bc5c8aa5b93b361d5bd2a3577fe5
* Make isWellFormedLanguageTag() actually case insensitiveNikki2023-11-151-3/+3
| | | | | | | | | | | | | | | | BCP 47 language tags are case insensitive. At the moment, isWellFormedLanguageTag() lowercases the language tag to be checked, but the regex contains uppercase characters, which means it will incorrectly return false for a language tag like "en-GB-oed". This changes the regex to use lowercase letters throughout, for consistency, since it doesn't use capital letters in other places where they would normally be used, but also makes it do a case-insensitive match instead of trying to make sure the case for the regex and language tag are the same. This should reduce the chance of it breaking if someone later re-adds capital letters to the regex. Change-Id: Iacf87d37c7ac515c350399f99e05e3f5bace9b90
* Language: minor cleanupReedy2023-10-021-14/+14
| | | | | | | * Remove unnecessary duplicate documentation * Code tweaks Change-Id: I9c8c190bee58195eace08cba18a51e4572896ef7
* Merge "Allow Bcp47Code as parameter to LanguageCode::bcp47ToInternal()"jenkins-bot2023-09-291-2/+8
|\
| * Allow Bcp47Code as parameter to LanguageCode::bcp47ToInternal()C. Scott Ananian2023-09-291-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This nominally takes a string-valued language code conforming to the BCP-47 standard, but this is often generated from a Bcp47Code object. Since the MediaWiki Language code implements Bcp47Code, we may have the case where we have a Language object in hand (but typed as a Bcp47Code not Language) and call Language::toBcp47Code() only to pass it to LanguageCode::bcp47ToInternal to convert it back to a mediawiki-internal code. We can save steps and be more efficient if allow the parameter to be a Bcp47Code object, and write a fast path for the special case where that Bcp47Code happens to be a Language object and we can simply call Language::getCode() to obtain the internal code. Change-Id: I24932449b8c40e3a5072748d87667184f4befa67
* | Languages: Add language crh-roAmir E. Aharoni2023-05-271-0/+1
|/ | | | | | | | Only Romanian is defined as fallback. See: https://translatewiki.net/w/i.php?title=User_talk:Amire80&oldid=11617782#Add_Fallback_language Bug: T336919 Change-Id: Ibe5a8227f30e78b04d4ed3a1476c06fc9e725422
* Use Bcp47Code when interfacing with ParsoidC. Scott Ananian2023-03-131-1/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is very easy for developers and maintainers to mix up "internal MediaWiki language codes" and "BCP-47 language codes"; the latter are standards-compliant and used in web protocols like HTTP, HTML, and SVG; but much of WMF production is very dependent on historical codes used by MediaWiki which in some cases predate the IANA standardized name for the language in question. Phan and other static checking tools aren't much help distinguishing BCP-47 from internal codes when both are represented with the PHP string type, so the wikimedia/bcp-47-code package introduced a very lightweight wrapper type in order to uniquely identify BCP-47 codes. Language implements Bcp47Code, and LanguageFactory::getLanguage() is an easy way to convert (or downcast) between Bcp47Code and Language objects. This patch updates the Parsoid integration code and the associated REST handlers to use Bcp47Code in APIs so that the standalone Parsoid library does not need to know anything about MediaWiki-internal codes. The principle has been, first, to try to convert a string to a Bcp47Code as soon as possible and as close to the original input as possible, so it is easy to see *why* a given string is a BCP-47 code (usually, because it is coming from HTTP/HTML/etc) and we're not stuck deep inside some method trying to figure out where a string we're given is coming from and therefore what sort of string code it might be. Second, we've added explicit compatibility code to accept MediaWiki internal codes and convert them to Bcp47Code for backward compatibility with existing clients, using the @internal LanguageCode::normalizeNonstandardCodeAndWarn() method. The intention is to gradually remove these backward compatibility thunks and replace them with HTTP 400 errors or wfDeprecated messages in order to identify and repair callers who are incorrectly using non-standard-compliant language codes in web standards (HTTP/HTML/SVG/etc). Finally, maintaining a code as a Bcp47Code and not immediately converting to Language helps us delay or even avoid full loading of a Language object in some cases, which is another reason to occasionally push Bcp47Code (instead of Language) down the call stack. Bug: T327379 Depends-On: I830867d58f8962d6a57be16ce3735e8384f9ac1c Change-Id: I982e0df706a633b05dcc02b5220b737c19adc401
* Merge "Tighten up function signature for LanguageCode::bcp47ToInternal()"jenkins-bot2023-01-311-1/+1
|\
| * Tighten up function signature for LanguageCode::bcp47ToInternal()C. Scott Ananian2023-01-301-1/+1
| | | | | | | | | | | | | | This was newly-added in 1.40 and it should have a modern tight signature. Change-Id: I34a058c1e4b141342cd1ea543e4d35ed141251e0
* | Minor adjustments for Names.php and LanguageCode.phpWinston Sung2023-01-291-2/+8
|/ | | | | | | | | kk has suppress-script: Cyrl in BCP 47, so kk-cyrl-kz won't be added, non-Cyrl kk-* would be converted kk-*-* to distinguish with kk(-Cyrl)-*. Bug: T321639 Change-Id: I6e58628f912222f73f8e94c01d5a3b43c2f15c30
* Add efficient LanguageCode::bcp47ToInternal() helperC. Scott Ananian2022-10-201-1/+52
| | | | | | | | | LanguageFactory::getLanguage() will accept *lowercased* BCP-47 codes, so this method is equivalent to LanguageFactory::getLanguage(strtolower($code))->getCode() but should be much more efficient in practice. Change-Id: I180765604d08ed57f655b69dfb32686f0b2a0dce
* Move isWellFormedLanguageTag from Language to LanguageCodeFomafix2022-08-301-0/+61
| | | | | | | | | | | | The static function isWellFormedLanguageTag is related to BCP 47 language codes not to the internal language codes or language names. The new function LanguageCode::isWellFormedLanguageTag uses type hints. THe explicit type cast (bool) is not necessary anymore. The old function Language::isWellFormedLanguageTag is now deprecated. Change-Id: I6431dbd82ed6dfcc2a7c3495eca025506551db05
* Replace deprecated Language::fetchLanguageNamesUmherirrender2021-12-051-1/+1
| | | | Change-Id: Iecd5481edb4dae6c7911157e24c32a51f4438ab2
* language: Clean up file headers and class-level docsTimo Tijhof2020-02-121-1/+0
| | | | | | | | | | | | | | | | | | | This follows-up d83fcce5cb6, which did something similar for includes/profiler/. * Ensure presence of license header. * Merge any file-level descriptions with the class block, where it gets seen in generated docs about that class. * Add any missing `@ingroup` tags to class blocks. * Remove remaining `@ingroup` from file blocks. These clutter the Doxygen pages with duplicate entries. * Fix some misspelled words from 61e0908fa29 and f136c2953c62. Change-Id: I5d21ec159766b799ba519da951d4f0716bae5f9f
* Convert some private static arrays to constantsMax Semenik2019-10-161-10/+8
| | | | | | | Remove @since for some private ones as we don't guarantee anything about private class members. Change-Id: Ifb898353c02082e9ef69d67f69339345c6cd154d
* Split some Language methods to LanguageNameUtilsAryeh Gregor2019-10-071-1/+0
| | | | | | | | | | | | | | | | | | | These are static methods that have to do with processing language names and codes. I didn't include fallback behavior, because that would mean a circular dependency with LocalisationCache. In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I also renamed fetchLanguageName(s) to getLanguageName(s). There is 100% test coverage for the code in the new class. This was previously committed as 2e52f48c2ed and reverted because it depended on e4468a1d6b6, which had to be reverted for performance issues. There should be no changes other than rebasing. Bug: T201405 Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
* Revert "Make LocalisationCache a service"Amir Sarabadani2019-08-261-0/+1
| | | | | | | | | | | | This reverts commits: - 76a940350d36c323ebedb4ab45cc81ed1c6b6c92 - b78b8804d076618e967c7b31ec15a1bd9e35d1d0 - 2e52f48c2ed8dcf480843e2186f685a86810e2ac - e4468a1d6b6b9fdc5b64800febdc8748d21f213d Bug: T231200 Bug: T231198 Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
* Split some Language methods to LanguageNameUtilsAryeh Gregor2019-08-231-1/+0
| | | | | | | | | | | | | | These are static methods that have to do with processing language names and codes. I didn't include fallback behavior, because that would mean a circular dependency with LocalisationCache. In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I also renamed fetchLanguageName(s) to getLanguageName(s). There is 100% test coverage for the code in the new class. Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
* language: Move some language-related classes to includes/language/Timo Tijhof2019-06-181-0/+204
Bug: T225756 Change-Id: Ica351483d83a3a912d58ebb194b30828541fbcf3