Tillägg:UniversalLanguageSelector

This page is a translated version of the page Extension:UniversalLanguageSelector and the translation is 39% complete.
Manual för MediaWikitillägg
UniversalLanguageSelector
Utgivningsstatus: stabil
Genomförande Användargränssnitt, Utseende , Betafunktioner
Beskrivning Verktyg som låter användare välja språk och konfigurera dess stöd på ett enkelt sätt.
Författare Wikimedias språkteam
Senaste versionen 2024-01-22
Kompatibilitetsregler Master maintains backward compatibility.
MediaWiki >= 1.40.0
Composer mediawiki/universal-language-selector
Licenser
Ladda ner Ingår i Language Extension Bundle
  • $wgULSWebfontsEnabled
  • $wgULSGeoService
  • $wgULSLanguageDetection
  • $wgULSAnonCanChangeLanguage
  • $wgULSEnable
  • $wgULSImeSelectors
  • $wgULSIMEEnabled
  • $wgULSNoWebfontsSelectors
  • $wgULSFontRepositoryBasePath
  • $wgULSCompactLanguageLinksBetaFeature
  • $wgULSNoImeSelectors
  • $wgULSPosition
Inte kompatibel med Internet Explorer 8 eller tidigare.
Quarterly downloads 188 (Ranked 37th)
Public wikis using 1,237 (Ranked 214th)
Översätt tillägget UniversalLanguageSelector om det finns tillgängligt på translatewiki.net
Ärenden Öppna ärenden · Rapportera en bugg

Den universala språkväljaren (Universal Language Selector) är ett verktyg för att låta användare välja språk och konfigurera stöd för det på att enkelt sätt. Där den används förknippas även funktionaliteten hos tilläggen WebFonts och Narayam (båda två har nämligen ogiltigförklarats till förmån för den universala språkväljaren). Läs Universell språkväljare för bakgrundsinformation och ytterligare information.

Användning

Den huvudsakligen målsättningen är att göra så att användare kan välja ett språk och konfigurera dess stöd på ett enkelt sätt.

Tillägget erbjuder följande funktioner:

  1. Flexibelt och enkelt sätt att välja ett språk från en stor uppsättning språk.
    1. Urvalet kan baseras på geografisk regionbaserad sökning.
    2. Sökningen kan baseras på ISO-språkkod, språknamn skrivet i nuvarande användargränssnittsspråk eller i dess egen skrift (autonym).
    3. Sökning mellan språk - söka efter språknamn med valfri skrift
    4. Automatisk ifyllning av språknamn
    5. Automatisk rättning av stavfel i söksträngar
    6. Geo-IP-baserat språkförslag
    7. Språkval baserat på användarens webbläsar-/operativsystemspråk
  2. Inmatningsmetoder
    Se Help:Extension:UniversalLanguageSelector/Input methods för fullständiga instruktioner.
    1. En lätt valbar samling inmatningsmetoder, klart och tillgängligt i alla redigeringsbara fält
    2. Erbjuder en stor uppsättning inmatningsmetoder för flera språk
    3. Inställningar för inmatningsmetoder efter språk
  3. Webbtypsnitt
    1. En stor samling typsnitt att välja för varje språk att använda som inbäddat typsnitt på sidan
    2. Typsnittsinställningar efter språk
 
Universella språkväljaren med geoip-baserat språkförslag för en användare från Indien
 
Språkinställningarna låter en registrerad användare gå till engelskspråkiga Wikipedia för att ändra gränssnitt till sitt eget språk.
 
En bengali-användare kan läsa innehåll från bengali Wikipedia trots bristen på typsnitt i sin dator. Webbtypsnitt tillhandahålls automatiskt för icke-latinska skriftspråk som det finns ett tillgängligt öppet typsnitt. Användaren kan bestämma att använda sina systemtypsnitt efter språk.
 
En hindi talare utan hindi-tangentbord konfigurerar inmatningsmetod för att skriva på sitt språk.
 
När man söker kan en användare växla mellan engelska och hindi.

Lägga till typsnitt

Supporting more languages is only a matter of including the proper fonts in the code. However, please note that we will add support only for freely licensed fonts, for example fonts licensed under GNU GPL, SIL OFL, etc. An example directory of such free fonts is Google Fonts [1] (not yet fully examined/exploited by the authors of this extension); see also the Open Font Library.

First of all, you need to find or produce such a free font (this is the most important part and you have to do it yourself); then, it has to be converted to the required formats, which are eot, ttf, woff; finally, you can file a request in Phabricator for the font to be added to the extension.

#Preparing webfonts below explains how to convert the fonts: basic knowledge about GNU/Linux based operating system is required; if you have difficulty in doing this, you can skip this step and ask someone else to do it for you on the same Phabricator request (of course this will slow down the process).

Preparing webfonts

Creating .woff:

Use https://github.com/bramstein/sfnt2woff-zopfli to generate woff from ttf file. This will produce a compressed woff file.

Creating .woff2:

Use https://github.com/google/woff2 to generate woff2 from ttf. This will produce a compressed woff2 file. Modern browsers support this format.

Create a font.ini file. Here's an example:

[AbyssinicaSIL]
languages=am*, ti*
version=1.200
license=OFL 1.1
licensefile=OFL.txt
url=http://scripts.sil.org/AbyssinicaSIL
ttf=AbyssinicaSIL.ttf
woff=AbyssinicaSIL.woff
woff2=AbyssinicaSIL.woff2
bold=AbyssinicaSIL Bold

[AbyssinicaSIL Bold]
ttf=AbyssinicaSIL-Bold.ttf
woff=AbyssinicaSIL-Bold.woff
woff2=AbyssinicaSIL-Bold.woff2

An asterisk (*) after a language code means that this font will be the default font for that language. If you just want the option to use this font for that language, don't use the asterisk.

After creating the files, do the following:

  1. Create a directory for the font under data/fontrepo/fonts.
  1. Put the ttf, woff, eot and font.ini files in that directory and add them to the source repository (git add).
  1. Go to the scripts/ directory and run php compile-font-repo.php.
  1. Commit the changes to the repository (git commit -a) 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.

Installation

  • Ladda ner och placera filen/filerna i en katalog som heter UniversalLanguageSelector i din extensions/-mapp.
    Utvecklare och personer som bidrar med kod borde istället installera tillägget från Git, med:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector
  • Lägg till följande kod längst ner i din LocalSettings.php -fil:
    wfLoadExtension( 'UniversalLanguageSelector' );
    
  •   Klart – Ta dig till Special:Version på din wiki för att bekräfta att tillägget har installerats ordentligt.


Vagrant-installering:

  • Om du använder Vagrant ska du installera med vagrant roles enable uls --provision

Updating LanguageNameIndex

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 Extension:CLDR 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.

Configuration

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

  • wgULSLanguages - an associative array where the keys are language codes and the values are language names in English.
  • wgULSAcceptLanguageList - 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.

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

The following variables can also be configured:

  • $wgULSGeoService - 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.
  • $wgULSEnable - 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.
  • $wgULSAnonCanChangeLanguage - 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 $wgULSEnable or $wgULSEnableAnon is set to false.
  • $wgULSIMEEnabled - Disable the input methods feature for all users by default. Can still be enabled manually by the user.
  • $wgULSPosition - The location and the form of the language selection trigger. The possible values are: personal: as a link near the username or the log in link in the personal toolbar (default). interlanguage: as an icon near the header of the list of interlanguage links in the sidebar.
  • $wgULSNoImeSelectors - Array of jQuery selectors of elements on which IME must not be enabled. eg: [ '#wpCaptchaWord' ];
  • $wgULSLanguageDetection - Whether to automatically detect the user's language from the Accept-Language header.

Position of ULS trigger

  • $wgULSPosition - The location and the form of the language selection trigger. The possible values are: personal: as a link near the username or the log in link in the personal toolbar (default). interlanguage: 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 uls-settings-trigger will act as a ULS trigger.

Overriding default fonts

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):

Caching configuration

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:

<FilesMatch "\.(gif|jpe?g|png|css|js|woff|svg|eot|ttf)$">

  • 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 font/woff .woff
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf

Page translation

UniversalLanguageSelector is one of the dependencies of the Tillägg:Translate 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.

Using Webfonts

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.

Alternate ways to load fonts

By specifying font-family

Inside the wiki text <span style="font-family:'YourFontName';">YourText</span>, 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.

By specifying language

Inside the wiki text <span lang="my">YourText</span>, 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.

Exempel:

<span lang=sux>𒄖𒉈𒅁𒌨𒅎</span>

ger texten renderad i kilskrift med akkadiskt typsnitt

𒄖𒉈𒅁𒌨𒅎

Se även