คู่มือ:ภาษา

From mediawiki.org
This page is a translated version of the page Manual:Language and the translation is 32% complete.
Outdated translations are marked like this.
i18n docs
ดูเพิ่มเติมที่ Manual:MediaWiki architecture#Languages (ควรรวมไว้ที่นี่หรือไม่)

ในมีเดียวิกิ มีภาษาหลายประเภท:

  • ภาษาเนื้อหาของไซต์ ($บริการ ContLang เป็น MediaWiki\MediaWikiServices::getContentLanguage ตาม $wgLanguageCode ) ซึ่งโดยทั่วไปแล้วควรจะเหมือนเดิมตราบใดที่วิกิยังมีอยู่
    • ตัวแปรภาษาของเนื้อหาไซต์ ($wgDefaultLanguageVariant ) เป็นรูปแบบเริ่มต้นเมื่อมีการใช้งาน LanguageConverter สำหรับภาษานั้น
  • ภาษาอินเทอร์เฟซผู้ใช้ ($contextSource->getLanguage() เดิมคือ $wgLang ) ซึ่งสามารถเปลี่ยนแปลงได้ตามต้องการหรือด้วย &uselang=xyz&uselang=xyz code> ใน URL แต่โดยทั่วไปยังคงเหมือนเดิมในขณะที่ใช้วิกิ
  • ภาษาเนื้อหาของหน้า อาจแตกต่างกันไปในแต่ละหน้า แม้ว่าไซต์และภาษาของผู้ใช้จะเหมือนกันก็ตาม มีการกำหนดไว้ใน getPageLanguage() ใน Title ซึ่งแสดงถึงภาษาที่ต้นฉบับข้อความวิกิเขียน
    • ภาษามุมมองหน้า หรือที่รู้จักกันในชื่อ ตัวแปรภาษาของผู้ใช้ ซึ่งเป็นตัวแปรภาษาของภาษาเนื้อหาของหน้าตามที่ผู้ใช้ต้องการ นอกจากนี้ยังสามารถตั้งค่าผ่านรหัส & ตัวแปร / รหัส (หรือ$VariantArticlePath) ใน URL (เช่นโดยการเลือกแท็บใดแท็บหนึ่ง) ถ้า มันเป็นตัวแปรของภาษาเนื้อหาของหน้าที่กําลังดู มันถูกกําหนดไว้ใน getPageViewLanguage() ใน ชื่อเรื่อง, ซึ่งแสดงภาษาที่เนื้อหา HTML ที่แสดงถูกเขียนขึ้น

It can also be set through &variant (or $wgVariantArticlePath ) in the URL (e.g. by selecting one of the tabs) if it is a variant of the content language of the page being viewed.

It's defined in getPageViewLanguage() in Title, representing what language the rendered HTML content is written in.

ทั้งสามนั้นเป็น language objects

รหัสภาษา

เพื่อไม่ให้สับสนกับ รหัสโครงการวิกิมีเดีย; ดูเพิ่มเติมที่ รหัสภาษา บนเมทา

รหัสภาษาเป็นตัวย่อมาตรฐานที่ถูกต้องสำหรับภาษาที่สนับสนุนโดยมีเดียวิกิ[1] ซึ่งใช้รหัสดังกล่าวเป็นตัวระบุมาตรฐานสำหรับภาษาต่างๆ (ส่วนใหญ่เป็นไปตาม ISO 639-3 ยกเว้นรหัสสองตัวอักษรจาก ISO 639-1 สำหรับโลแคล "ที่จัดตั้งขึ้น") และเปิดเผยหรือกำหนดให้ใช้ในหลายจุดของอินเทอร์เฟซและโค้ด[2]

A language code is a valid standard abbreviation for a language supported by MediaWiki,[3] which uses such codes as standard identifiers for languages (mostly in accordance with ISO 639-3, except two-letter codes from ISO 639-1 for "established" locales) and exposes or requires them in many points of the interface and code.[4]

สำหรับตัวอย่างด้านล่าง, MediaWiki:Message/ar, ar เป็นรหัสภาษาสำหรับ العربية

ความสม่ําเสมอกับมาตรฐาน Unicode เป็นสิ่งจำเป็นเพื่อให้การสนับสนุนภาษาที่ดี โดยเฉพาะอย่างยิ่งในการร่วมมือกับ CLDR; การมีรหัส ISO 639-3 เป็นหนึ่ง ข้อกำหนดสำหรับภาษาที่จะเพิ่มไปยังตำแหน่งที่ตั้งมีเดียวิกิ

Names.php

Names.php เป็นรีจิสทรีหลักของภาษาที่สนับสนุนโดย MediaWiki ซึ่งไม่เหมือนกับภาษาที่ MediaWiki จะแสดง l10n (ไฟล์ JSON) หรือภาษาที่ MediaWiki รู้ชื่อ (ผ่าน CLDR ) โปรดทราบ!

ภาษาสำรอง

โซ่ (chain) สำรอง (บางบรรทัดที่แสดงไม่ถูกต้องเนื่องจากมีภาษาสองภาษาในตัวเลือกสำรอง ตรวจสอบว่ามีการเชื่อมต่ออยู่ใน เวอร์ชันข้อความ)

บางภาษาในมีเดียวิกิมีสิ่งที่เรียกว่า "ลำดับทางเลือก" นี่คือที่ที่ MediaWiki จะกลับไปใช้ภาษาอื่นหากไม่พบสิ่งที่ต้องการ ตัวอย่างนี้คือรหัสภาษา frc (Cajun French) ซึ่งกลับไปใช้รหัสภาษา fr (ภาษาฝรั่งเศส) เหตุผลก็คือบางครั้งภาษาก็ไม่มีข้อความที่กำหนดไว้ทั้งหมด This is where MediaWiki will fall back on a different language if it cannot find what it needs. An example of this is the language code frc (Cajun French), which falls back on the language code fr (French). The reason for this is that sometimes languages don't have all messages defined in them.

ทางเลือกของภาษาสามารถพบได้ในไฟล์ languages/messages/MessagesXX.php ที่เกี่ยวข้อง เช่น MessagesFrc.php คุณสามารถ ค้นหารหัสสำหรับการใช้งานทั้งหมด นอกจากนี้ยังมีรายการธรรมดาจาก กันยายน พ.ศ. 2563 ใน นี่เป็นความเห็นฟาบริเคเตอร์

ภาษาของเนื้อหาเว็บไซต์

การดู/รับภาษาของเนื้อหาไซต์

JavaScript :

mw.config.get( 'wgContentLanguage' );

ภาษาอินเทอร์เฟซผู้ใช้

เวอร์ชันมีเดียวิกิ:
1.18
ค่าเริ่มต้น

>getLanguage()

ตั้งค่าผ่าน
  • Special:Preferences
  • &uselang=zxx ใน URL (ดูที่ uselang)
  • &variant=xy (หรือ $wgVariantArticlePath ) ใน URL ถ้า มันเป็นตัวแปรของภาษาผู้ใช้ของคุณ
ปัญหา
เนื่องจากข้อความส่วนต่อประสานอาจมาจากภาษาทางเลือก แต่ไม่มีการส่งคืนภาษา จึงไม่ทราบภาษาจริงของแต่ละข้อความ

ภาษาเนื้อหาของหน้า

เวอร์ชันมีเดียวิกิ:
1.18
ค่าเริ่มต้น
  • $wgLang ในหน้าพิเศษ
  • ภาษาอังกฤษสำหรับหน้า CSS และ JS
  • For MediaWiki namespace pages, the language depends on the subpage. For example, MediaWiki:Message/ar will be set to Arabic (ar), and MediaWiki:Message will be ContentLanguage.
  • หน้าอื่น ๆ ทั้งหมดคือ $wgContLang โดยค่าเริ่มต้น
การกำหนดค่า
ส่วนขยายสามารถเปลี่ยนหน้าอื่นๆ ทั้งหมดผ่าน PageContentLanguage hook ค่าสำหรับหน้าพิเศษ, หน้าเนมสเปซ CSS, JS และ MediaWiki ไม่สามารถแทนที่ได้
ตัวอย่าง
ส่วนขยายการแปล ใช้สำหรับคุณลักษณะการแปลหน้า ดู translatewiki:Project:About/ar เป็นคำแปลของ translatewiki:Project:About ทิศทางของหน้าจึงถูกตั้งค่าเป็นขวาไปซ้ายสำหรับภาษาอาหรับอย่างถูกต้อง
เวอร์ชันมีเดียวิกิ:
1.24
เปลี่ยนภาษาหน้าด้วยตนเอง
การเลือกภาษาของหน้าสามารถทำได้โดยใช้ Special:PageLanguage ตั้งแต่ MediaWiki 1.24
ผู้ใช้สามารถเปลี่ยนภาษาเนื้อหาของหน้าซึ่งเป็นค่าเริ่มต้นของภาษา Wiki ($wgContLang) ภาษาของหน้าในเนมสเปซมีเดียวิกิ (MediaWiki) ไม่สามารถเปลี่ยนแปลงได้
ต้องเปิดใช้งานคุณลักษณะนี้ด้วย $wgPageLanguageUseDB = true และต้องให้สิทธิ์ pagelang แก่กลุ่มสิทธิ์ผู้ใช้ Wiki (ผู้ที่สามารถเปลี่ยนแปลงภาษาของหน้าได้)
การเปลี่ยนภาษาของหน้าทำให้หน้าการแปลต้นฉบับและหน่วยของหน้าถูกย้ายไปยังภาษาเป้าหมายที่ถูกต้อง ในกรณีที่หน้าแปลภาษาเป้าหมายมีอยู่แล้ว ไม่อนุญาตให้เปลี่ยนภาษา
Matching API สามารถพบได้ใน API:SetPageLanguage
มันกำหนดอะไร?
  • ใน SkinTemplate จะเพิ่ม <div lang="xyz" dir="ltr/rtl" class="mw-content-ltr/rtl"></div> รอบข้อความหน้า dir แอตทริบิวต์ตั้งค่าที่ถูกต้อง ทิศทางการเขียน แอตทริบิวต์ lang จะเป็นรหัสรูทเสมอ เช่น "de" แม้ว่าจะกำหนด "de-formal" ก็ตาม
    สำหรับหน้าไฟล์จะถูกตั้งค่าเป็น ImagePage.php เนื่องจากมี HTML จำนวนมากในภาษาของผู้ใช้
  • ใน Parser.php จะกำหนดหมายเลขสารบัญ (TOC) และสิ่งต่างๆ เช่น ไวยากรณ์ แม้ว่าจะไม่ค่อยเกี่ยวข้องกันเป็นส่วนใหญ่ หากต้องการทำเช่นนั้นเท่านั้น ให้ใช้ parserOptions->setTargetLanguage()
  • ทิศทางของข้อความต่าง (DifferenceEngine) ถูกตั้งค่าเป็นภาษาเนื้อหาของหน้า ในบางกรณีสิ่งนี้ไม่เหมือนกัน ซึ่งในกรณีนี้ $diffEngineObject->setTextLanguage( $code ) สามารถใช้ได้
  • ตั้งแต่ 1.19 มันยังตั้งเวลาและการจัดรูปแบบตัวเลข magic words รวมถึง DIRECTIONMARK แต่ไม่ใช่ NAMESPACE(E) เพราะนั่นขึ้นอยู่กับภาษาของไซต์จริงๆ โปรดทราบว่าการรวมเทมเพลตที่ทำเครื่องหมายเป็นภาษา A ไว้ในหน้าที่มีภาษา B จะถูกแยกวิเคราะห์ด้วยภาษา B ในหน้านั้น
หลายภาษาในหน้าเดียว
ในทางทฤษฎีแล้ว หลายภาษาในหน้าเดียวไม่รองรับ แต่แท็ก <div lang="xyz" dir="ltr/rtl" class="mw-content-ltr/rtl"> แบบธรรมดาสามารถใช้เพื่อทำเครื่องหมายข้อความว่าเขียนในภาษาอื่น หากใช้คลาส CSS รายการ ul/ol และส่วนแก้ไขจะแสดงอย่างสวยงามเมื่อแท็ก dir อยู่ตรงข้ามกับค่าของภาษาเนื้อหาของหน้า อย่างไรก็ตาม สิ่งที่กำหนดไว้ใน parser เช่น TOC และคำวิเศษ จะไม่เปลี่ยนแปลง
กำลังดู/รับภาษาของหน้า
  • JavaScript: mw.config.get( 'wgPageContentLanguage' ) - โปรดทราบว่าเมื่อเช่น การดูประวัติหน้าจะส่งคืนภาษาของหน้าเว็บที่เป็นประวัติ ในขณะที่หน้าประวัติไม่มีคลาส mw-content-ltr/rtl เช่น. ทั้ง "/wiki/Page" และ "/w/index.php?title=Page&action=history" จะส่งคืนภาษาของ "หน้า" 1.19+
  • ภาษาของเนื้อหาหน้าระบุไว้ในมุมมองข้อมูลของเพจ (action=info ลิงก์ในกล่องเครื่องมือ)

1.21+

โครงสร้างโค้ด

อันดับแรก คุณมีออบเจ็กต์ภาษาในสกุลเงิน Language.php ออบเจ็กต์นี้มี สตริงข้อความ ที่แปลเป็นภาษาท้องถิ่นได้ทั้งหมด เช่นเดียวกับการตั้งค่าเฉพาะภาษาที่สำคัญอื่นๆ และการทำงานที่กำหนดเอง (ตัวพิมพ์ใหญ่ ตัวพิมพ์เล็ก วันที่พิมพ์ การจัดรูปแบบตัวเลข ทิศทาง, กฎไวยากรณ์ที่กำหนดเอง ฯลฯ )

อ็อบเจ็กต์ถูกสร้างขึ้นจากแหล่งที่มาสองแหล่ง: เวอร์ชันย่อยของตัวมันเอง (คลาส (classes)) และไฟล์ข้อความ (ข้อความ (messages))

นอกจากนี้ยังมีคลาส (class) MessageCache ซึ่งจัดการการป้อนข้อความผ่านเนมสเปซ MediaWiki Most internationalisation is nowadays done via Manual:Messages API objects and by using the wfMessage() shortcut function, which is defined in includes/GlobalFunctions.php. Legacy code might still be using the old wfMsg*() functions, which are now considered deprecated in favor of the above-mentioned Message objects.

ดูเพิ่มที่ Manual:Messages API

Language objects

There are two ways to get a language object. You can use the globals $wgLang and ContentLanguage service (MediaWiki\MediaWikiServices::getContentLanguage) for user interface and content language respectively. For an arbitrary language you can construct an object by using $languageFactory->getLanguage( 'en' ) by replacing en with the code of the language. You can get $languageFactory, an object of the MediaWiki\Languages\LanguageFactory class, using Dependency Injection . You can also use wfGetLangObj( $code ); if $code could already be a language object. The list of codes is in includes/languages/data/Names.php.

Language objects are needed for doing language-specific functions, most often to do number, time and date formatting, but also to construct lists and other things. There are multiple layers of caching and merging with #Fallback languages, but the details are irrelevant in normal use.

Old local translation system

With MediaWiki 1.3.0, a new system was set up for localising MediaWiki. Instead of editing the language file and asking developers to apply the change, users could edit the interface strings directly from their wikis. This is the system in use as of August 2005. People can find the message they want to translate in Special:AllMessages and then edit the relevant string in the MediaWiki: namespace. Once edited, these changes are live. There was no more need to request an update, and wait for developers to check and update the file.

The system is great for Wikipedia projects; however a side effect is that the MediaWiki language files shipped with the software are no longer quite up-to-date, and it is harder for developers to keep the files on meta in sync with the real language files.

As the default language files do not provide enough translated material, we face two problems:

  1. New Wikimedia projects created in a language which has not been updated for a long time, need a total re-translation of the interface.
  1. Other users of MediaWiki (including Wikimedia projects in the same language) are left with untranslated interfaces.

This is especially unfortunate for the smaller languages which don't have many translators.

This is not such a big issue anymore, because translatewiki.net is advertised prominently and used by almost all translations. Local translations still do happen sometimes but they're strongly discouraged. Local messages mostly have to be deleted, moving the relevant translations to translatewiki.net and leaving on the wiki only the site-specific customisation; there's a huge backlog especially in older projects, this tool helps with cleanup.

Keeping messages centralised and in sync

English messages are very rarely out of sync with the code. Experience has shown that it's convenient to have all the English messages in the same place. Revising the English text can be done without reference to the code, just like translation can. Programmers sometimes make very poor choices for the default text.

What can be localised

So many things are localisable on MediaWiki that not all of them are directly available on translatewiki.net : see translatewiki:Translating:MediaWiki. If something requires a developer intervention on the code, you can request it on Phabricator, or ask at translatewiki:Support if you don't know what to do exactly.

Graph of language fallback
  • Fallback languages (that is, other more closely related language(s) to use when a translation is not available, instead of the default fallback, which is English)
  • Directionality (left to right or right to left, RTL)
  • Direction mark character depending on RTL
  • Arrow depending on RTL
  • Languages where italics cannot be used
  • Number formatting (comma-ify, i.e. adding or not digits separators; transform digits; transform separators)[5]
  • Truncate (multibyte)
  • Grammar conversions for inflected languages
  • Plural transformations
  • Formatting expiry times[clarification needed]
  • Segmenting for diffs (Chinese)
  • Convert to variants of language (between different orthographies, or scripts)
  • Language specific user preference options
  • Link trails and link prefix - $linkTrail. These are letters that can be glued after/before the closing/opening brackets of a wiki link, but appear rendered on the screen as if part of the link (that is, clickable and in the same colour), e.g.: [[foo]]bar. By default the link trail is "a-z"; you may want to add the accentuated or non-Latin letters used by your language to the list.
  • Language code (preferably used according to the latest RFC in standard BCP 47, currently RFC 5646, with its associated IANA database. Avoid deprecated, grandfathered and private-use codes: look at what they mean in standard ISO 639, and avoid codes assigned to collections/families of languages in ISO 639-5, and ISO 639 codes which were not imported in the IANA database for BCP 47)
  • Type of emphasising
  • The Cite extension has a special page file per language, cite_text-zyx for language code zyx.

Neat functionality:

  • I18N sprintfDate
  • การจัดรูปแบบเลขโรมัน

เนมสเปซ

Currently making namespace name translations is disabled on translatewiki.net, so you need to do this yourself in Gerrit, or file a ฟาบริเคเตอร์ task asking for someone else to do it.[6]

To allow custom namespaces introduced by your extension to be translated, create a MyExtension.i18n.namespaces.php file that looks like this:

<?php
/**
 *  Translations of the namespaces introduced by MyExtension.
 *
 * @file
 */

$namespaceNames = [];

//  For wikis where the MyExtension extension is not installed.
if( !defined( 'NS_MYEXTENSION' ) ) {
	define( 'NS_MYEXTENSION', 2510 );
}

if( !defined( 'NS_MYEXTENSION_TALK' ) ) {
	define( 'NS_MYEXTENSION_TALK', 2511 );
}

/** English */
$namespaceNames['en'] = [
	NS_MYEXTENSION => 'MyNamespace',
	NS_MYEXTENSION_TALK => 'MyNamespace_talk',
];

/** Finnish (Suomi) */
$namespaceNames['fi'] = [
	NS_MYEXTENSION => 'Nimiavaruuteni',
	NS_MYEXTENSION_TALK => 'Keskustelu_nimiavaruudestani',
];

Then load it from the extension.json file using ExtensionMessagesFiles like this:

{
	"name": "MyExtension",
	"version": "0.0.1",
	"descriptionmsg": "myextension-desc",
    "ExtensionMessagesFiles": {
		"MyExtensionNamespaces": "MyExtension.i18n.namespaces.php"
	}
}

Now, when a user installs MyExtension on their Finnish (fi) wiki, the custom namespace will be translated into Finnish magically, and the user doesn't need to do a thing!

Also remember to register your extension's namespace(s) on the extension default namespaces page.

นามแฝงหน้าพิเศษ

See the manual page for Special pages for up-to-date information. The following does not appear to be valid.


Create a new file for the special page aliases in this format:

<?php
/**
 * Aliases for the MyExtension extension.
 *
 * @file
 * @ingroup Extensions
 */

$aliases = [];

/** English */
$aliases['en'] = [
	'MyExtension' => [ 'MyExtension' ]
];

/** Finnish (Suomi) */
$aliases['fi'] = [
	'MyExtension' => [ 'Lisäosani' ]
];

Then load it from the extension.json file using ExtensionMessagesFiles like this:

{
	"name": "MyExtension",
	"version": "0.0.1",
	"descriptionmsg": "myextension-desc",
    "ExtensionMessagesFiles": {
		"MyExtensionAlias": "MyExtension.i18n.alias.php"
	}
}

When your special page code uses either SpecialPage::getTitleFor( 'MyExtension' ) or $this->getTitle() (in the class that provides Special:MyExtension), the localised alias will be used, if it's available.

Namespace name aliases

Namespace name aliases are additional names which can be used to address existing namespaces. They are rarely needed, but not having them when they are, usually creates havoc in existing wikis.

You need namespace name aliases:

  1. When a language has variants, and these variants spell some namespaces differently, and you want editors to be able to use the variant spellings.

Variants are selectable in the user preferences. Users always see their selected variant, except in wikitext, but when editing or searching, an arbitrary variant can be used.

  1. When an existing wiki's language, fall back language(s), or localisation is changed, with it are changed some namespace names.

So as not to break the links already present in the wiki, that are using the old namespace names, you need to add each of the altered previous namespace names to its namespace name aliases, when, or before, the change is made.

The generic English namespace names are always present as namespace name aliases in all localisations, so you need not, and should not, add those.

Aliases can't be translated on translatewiki.net , but can be requested there or on bugzilla : see translatewiki:Translating:MediaWiki#Namespace name aliases.

การตั้งค่าภูมิภาค

Some linguistic settings vary across geographies; MediaWiki doesn't have a concept of region, it only has languages and language variants.

These settings need to be set once as a language's default, then individual wikis can change them as they wish in their configuration.

Time and date formats

Time and dates are shown on special pages and alike. The default time and date format is used for signatures, so it should be the most used and most widely understood format for users of that language. Also anonymous users see the default format. Registered users can choose other formats in their preferences.

If you are familiar with PHP's time() format, you can try to construct formats yourself. MediaWiki uses a similar format string, with some extra features. If you don't understand the previous sentence, that's OK. You can provide a list of examples for ผู้พัฒนา .

หมายเหตุ

  1. ดู m:Special:MyLanguage/Language codes
  2. ถึงแม้สิ่งนี้ การตรวจสอบรหัสภาษาในปี 2555 ยังไม่ได้รับการแก้ไข ปัญหา. ดู Niklas Laxström, [$lang-valid Language validation in MediaWiki], 28 สิงหาคม 2012
  3. See includes/languages/data/Names.php.
  4. Despite this, as of 2012 language codes validation is not yet a solved problem. See Niklas Laxström, Language validation in MediaWiki, August 28th, 2012.
  5. These are configured by language in the respective language/classes/LanguageXx.php or language/messages/MessagesXx.php files.
  6. https://gerrit.wikimedia.org/r/211677

ดูเพิ่ม

  • Obtaining language names from codes is possible using the core function {{#language:<code>}} documented in magic words