| 1 |
[![Latest Stable Version]](https://packagist.org/packages/wikimedia/bcp-47-code) [![License]](https://packagist.org/packages/wikimedia/bcp-47-code) |
| 2 |
|
| 3 |
Bcp47Code |
| 4 |
===================== |
| 5 |
|
| 6 |
Simple interface representing languages which have a BCP 47 code. |
| 7 |
|
| 8 |
This abstracts the details of a "language" object in MediaWiki (or your |
| 9 |
code) and exposes only the ability to convert this opaque object to |
| 10 |
an interoperable [BCP 47] code, which is the standard used in [HTML] |
| 11 |
and [HTTP]. |
| 12 |
|
| 13 |
The [BCP 47] standard was originally [RFC 4647],and is now |
| 14 |
[maintained by the IETF based on the IANA language registry](https://en.wikipedia.org/wiki/IETF_language_tag). |
| 15 |
|
| 16 |
Additional documentation about this library can be found on |
| 17 |
[mediawiki.org](https://www.mediawiki.org/wiki/Bcp47Code). |
| 18 |
|
| 19 |
|
| 20 |
Usage |
| 21 |
----- |
| 22 |
|
| 23 |
```php |
| 24 |
use Wikimedia\Bcp47Code\Bcp47Code; |
| 25 |
|
| 26 |
class YourCode { |
| 27 |
public function generateHtml(Bcp47Code $language, $content) { |
| 28 |
return "<html><body lang='" . $language->toBcp47() . "'>" . |
| 29 |
"$content</body></html>"; |
| 30 |
} |
| 31 |
} |
| 32 |
``` |
| 33 |
|
| 34 |
|
| 35 |
Running tests |
| 36 |
------------- |
| 37 |
|
| 38 |
``` |
| 39 |
composer install |
| 40 |
composer test |
| 41 |
``` |
| 42 |
|
| 43 |
History |
| 44 |
------- |
| 45 |
|
| 46 |
This library was first introduced in MediaWiki 1.40 as a way to abstract |
| 47 |
the internal MediaWiki Language class in a way that could be used by |
| 48 |
external libraries such as [Parsoid], as well as making the interfaces |
| 49 |
between BCP 47 users (such as HTML and HTTP handlers) and core strongly |
| 50 |
typed and clear by using this opaque interface object. This avoids |
| 51 |
confusion between strings representing "MediaWiki internal language codes" |
| 52 |
(case-sensitive, usually lower-case) and strings representing "BCP 47 codes" |
| 53 |
(case-insensitive, often mixed-case). |
| 54 |
|
| 55 |
|
| 56 |
--- |
| 57 |
[BCP 47]: https://www.rfc-editor.org/info/bcp47 |
| 58 |
[RFC 4647]: https://www.rfc-editor.org/info/rfc4647 |
| 59 |
[HTML]: https://www.w3.org/International/articles/language-tags/ |
| 60 |
[HTTP]: https://httpwg.org/specs/rfc9110.html#field.accept-language |
| 61 |
[Latest Stable Version]: https://poser.pugx.org/wikimedia/bcp-47-code/v/stable.svg |
| 62 |
[License]: https://poser.pugx.org/wikimedia/bcp-47-code/license.svg |