Extension:UniversalLanguageSelector/zh

通用语言选择器（Universal Language Selector）是一个允许用户选择语言，并以更容易的方式配置其支持的工具. 在使用的地方，它还附带了和扩展的功能（不推荐使用这两种扩展，而推荐使用Universal Language Selector）. 参见以了解背景及额外信息.

用法
主要目的是让用户以一种简单的方法选择并配置支持用户语言.

该扩展提供了以下功能：


 * 1) 从众多语言中选择一种语言的灵活便捷的方法.
 * 2) 可根据地理区域进行选择浏览、搜索.
 * 3) 搜索可以基于ISO语言代码、以当前用户界面语言编写的语言名称或其自己的脚本（自动命名）
 * 4) 跨语言搜索-使用任何脚本搜索任意的语言
 * 5) 语言名称的自动补全
 * 6) 自动更正搜索字符串中的拼写错误
 * 7) 基于地理位置的语言建议
 * 8) 基于用户浏览器/操作系统语言的语言选择
 * 9) 输入法
 * 有关完整说明，请参阅
 * 1) 一个易于选择的输入法集合，在每个可编辑字段中随时可用
 * 2) 为各种语言提供一系列输入法
 * 3) * 拓展:Narayam#Supported scheme 提供了一个过时的列表
 * 4) 每种语言的输入法首选项
 * 5) 网络字体
 * 6) 为每种语言选择不同字体以用作页面的嵌入字体
 * 7) * 拓展:WebFonts#Supported languages 提供了一个过时的列表
 * 8) * 你可以浏览所有字体包括
 * 9) 每种语言的字体首选项



添加字体
支持更多语言只需在代码中包含正确的字体. 但是，请注意，我们将仅添加对免费许可字体的支持，例如在 GNU GPL、SIL OFL 等下许可的字体. 此类免费字体的示例目录是 Google Fonts （不是 但已被此扩展程序的作者充分检查/利用）； 另见 开源字体库.

首先，你需要找到或制作这样一个免费的字体（这是最重要的部分，你必须自己做）； 然后，必须将其转换为所需的格式，即eot、ttf、woff； 最后，您可以在 Phabricator 中 file a request 将字体添加到扩展中.

网络字体 下面解释了如何转换字体：需要有基于 GNU/Linux 操作系统的基本知识； 如果您在执行此操作时遇到困难，您可以跳过此步骤并在同一个 Phabricator 请求中请其他人为您执行此操作（当然这会减慢该过程）.

准备网页字体（webfonts）
创建.woff2：

使用 https://github.com/google/woff2 从 ttf 生成 woff2， 这将生成一个压缩的 woff2 文件. 主流的浏览器支持这种格式.

创建一个font.ini文件，这里有个例子：

语言代码后的星号 表示该字体将是该语言的默认字体. 如果您只想选择将此字体用于该语言，请不要使用星号.

创建文件后，执行以下操作：


 * 1) 在 data/fontrepo/fonts 下为字体创建一个目录.
 * 2) 将 ttf、woff、eot 和 font.ini 文件放在该目录中，并将它们添加到源存储库（ ）.
 * 3) 进入 目录并运行.
 * 1) Commit the changes to the repository  and submit them according to the Git workflow.

Adding support for a new key mapping (input method)
Follow the instructions on the jquery.ime github wiki, but file requests in the Wikimedia-extensions-UniversalLanguageSelector Phabricator product.

更新语言名称索引
For performing cross language search, searching autonyms, language data needs to be populated. ULS comes with a pre-populated language name index(data/langnames.ser). In case you want to update it, install and update the data with the following command.

php UniversalLanguageSelector/data/LanguageNameIndexer.php and verify that langnames.ser file gets generated in ULS/data/ folder.

配置
The following variables are created automatically during initialization and can be used from JavaScript using mw.config.get( NAME ):


 * - an associative array where the keys are language codes and the values are language names in English.
 * - an array of language codes from the user's Accept-Language value. These are the languages selected in the user's browser preferences.

For serving fonts, you might want to add the following mime types to your webserver if not already there. This guide might help.

 application/x-font-woff .woff application/vnd.ms-fontobject .eot application/x-font-ttf .ttf

The following variables can also be configured:


 * - ULS can use geolocation services to suggest languages based on the country the user is visiting from. Setting this to false will prevent builtin geolocation from being used. You can provide your own geolocation by setting window. Geo to object which has key 'country_code' or 'country'. If set to true, it will query Wikimedia's geoip service. The service should return jsonp that uses the supplied callback parameter. Defaults to http://freegeoip.net/json/ (warning: this website has shut down its API) and expects the same format.
 * - Enable language selection, compact language links, input methods and webfonts for everyone, unless the behavior is overridden by the configuration variables below.  Even if false the classes and resource loader modules are registered for the use of other extensions. Language changing via cookie or setlang query parameter is not possible.
 * - Allow anonymous users to change language with cookie and setlang query param. Do not use if you are caching anonymous page views without taking cookies into account. Does not have any effect if either of   or   is set to false.
 * - Disable the input methods feature for all users by default. Can still be enabled manually by the user.
 * - The location and the form of the language selection trigger. The possible values are: : as a link near the username or the log in link in the personal toolbar (default).  : as an icon near the header of the list of interlanguage links in the sidebar.
 * - Array of jQuery selectors of elements on which IME must not be enabled. eg:
 * - Whether to automatically detect the user's language from the Accept-Language header.

ULS触发位置

 * - The location and the form of the language selection trigger. The possible values are: : as a link near the username or the log in link in the personal toolbar (default).  : as an icon near the header of the list of interlanguage links in the sidebar.

It is also possible to have ULS trigger anywhere in the screen. An element with  will act as a ULS trigger.

首要默认字体
ULS has a large font repository to serve as webfonts. Sometimes there are multiple fonts for a language and there is a default font for each language/script. The order of fonts or default font can be overridden as follows using global scripts (MediaWiki:Common.js) or personal scripts (Special:MyPage/common.js):

缓存配置
To ensure that the web fonts files are cached on the clients' machines, font file types must be added to the web server configuration. In Apache2 this consists of:


 * Adding font file extensions to the FileTimes regex at FilesMatch for the relevant directory, example:
 * Adding ExpiresByType values to the relevant MIME types, similarly to image MIME types.
 * Note that there's no standard MIME type for TTF. application/x-font-ttf is used for Wikimedia.
 * Adding the MIME types:

 AddType application/x-woff .woff AddType application/vnd.ms-fontobject .eot AddType application/x-font-ttf .ttf

For a full example see the caching configuration update done for the Wikimedia cluster.

页面翻译
UniversalLanguageSelector is one of the dependencies of the extension, which uses it for several language selection features. One of it is the MyLanguage system for links, which depends on the interface language of the user, but more can be configured: see Page translation feature.

使用网页字体
User can choose webfonts for a language from the Language settings -> Display settings. By default, the first font in that menu will be applied to the wiki. A user can change the font and it will be remembered across the pages. Optionally user can disable the font embedding too by selecting system font.

If the font is available in user's local system, font will not be downloaded from the mediawiki server. It will be taken from the user's computer. Otherwise, font will be downloaded from the server only once. ie when the user selects the font first time. Next time onwards, font will be taken from the local cache.

通过指定字体系列
Inside the wiki text YourText, webfonts extension will check whether the font is available with the extension, if so it will download it to the client. So the reader will not face any difficulty in reading the text even if the font specified is not available in their computer.

通过指定语言
Inside the wiki text YourText, webfonts extension will check whether any font is available for the given language with the extension, if so it will download it to the client. So the reader will not face any difficulty in reading the text even if the font specified is not available in their computer. If there are multiple fonts for the language, the default font will be used. If default font is not preferred, use the font-family approach to specify the font. If the tag has both lang and font-family definitions, font-family get precedence.

例子：

𒄖𒉈𒅁𒌨𒅎

gives the text rendered in Cuneiform using Akkadian font

𒄖𒉈𒅁𒌨𒅎

另见

 * Extension:Google Translator
 * Extension:Google Translator
 * Extension:Google Translator
 * Extension:Google Translator
 * Extension:Google Translator