Manual:LanguageSelector
In Jan, 2026, we added Codex based language selectors to MediaWiki core (v1.46.0).
The following components are available:
LookupLanguageSelector- Based on the Codex Lookup component. Allows selection of a single language. Available since MediaWiki 1.46.0.MultiselectLookupLanguageSelector- Similar to theLookupLanguageSelectorbut allows selection of multiple languages. Available since MediaWiki 1.46.0.
The components are maintained by the Language and Product Localization team.
LookupLanguageSelector
[edit]A Codex Lookup based component that allows users to select a language. Available since MediaWiki 1.46.0
The default list of languages is based on what's supported by MediaWiki. The LanguageNameUtils::getLanguageNames() is used to load the list of languages.
Vue.js usage
[edit]Within a Vue application, import and use the component directly.
const { LookupLanguageSelector } = require( 'mediawiki.languageselector' );
// In your Vue component:
// components: { LookupLanguageSelector }
<lookup-language-selector
v-model:selected="currentLanguage"
:search-api-url="apiUrl"
:selectable-languages="languages"
/>
Props
[edit]| Prop | Type | Default | Description |
|---|---|---|---|
selected
|
String
|
null
|
The selected language code (e.g., 'en'). Using v-model:selected is recommended to handle updates automatically.
|
searchApiUrl
|
String
|
Required | The API URL to use for searching languages (e.g., /w/api.php). required.
|
selectableLanguages
|
Object
|
null
|
An object mapping language codes to language names (e.g., { en: 'English', es: 'Español' }). If not provided, the default list of supported languages is used.
|
debounceDelayMs
|
Number
|
300
|
The debounce delay in milliseconds for the search input. |
menuConfig
|
Object
|
{}
|
Configuration object passed to the underlying Codex lookup menu. See the Codex Lookup documentation |
placeholder
|
String
|
null
|
Placeholder displayed inside the textbox. |
Events
[edit]| Event | Properties | Description |
|---|---|---|
update:selected
|
value (String)
|
Emitted when the selected language changes. The payload is the new language code. This event supports v-model:selected.
|
Slots
[edit]| Slot Name | Props | Description |
|---|---|---|
menu-item
|
menuItem (Object), languageCode (String), languageName (String)
|
Customizes the content of each item in the results menu. |
no-results
|
searchQuery (String)
|
Customizes the message displayed when no languages match the search query. Default is the 'languageselector-no-results' |
Examples
[edit]- In the Translate extension: 1210647: AggregateGroupsSpecialPage: Use LookupLanguageSelector | https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Translate/+/1210647
JavaScript Usage
[edit]The module mediawiki.languageselector must be loaded. It exports a factory function, getLookupLanguageSelector, which creates a Vue application instance that can be mounted to a DOM element.
mw.loader.using( 'mediawiki.languageselector' ).then( function ( require ) {
const { getLookupLanguageSelector } = require( 'mediawiki.languageselector' );
const mySelector = getLookupLanguageSelector( {
// Configuration options
selectedLanguage: 'en',
onLanguageChange: function ( langCode ) {
console.log( 'Selected language:', langCode );
}
} );
// Mount the selector to an element on the page
mySelector.mount( '#my-language-selector-container' );
} );
Configuration
[edit]The getLookupLanguageSelector function accepts a configuration object with the following properties:
| Property | Type | Default | Description |
|---|---|---|---|
selectedLanguage
|
string
|
null
|
The language code of the initially selected language (e.g., 'en', 'fr'). |
selectableLanguages
|
Object
|
null
|
An object mapping language codes to language names (e.g., { en: 'English', es: 'Español' }). If null, a built-in list of supported languages is used.
|
apiUrl
|
string
|
Current wiki API | The URL of the API to use for searching languages (e.g., /w/api.php).
|
menuConfig
|
Object
|
{}
|
Configuration object passed to the underlying Codex lookup menu. See the Codex Lookup documentation for details. |
placeholder
|
String
|
null
|
Placeholder displayed inside the textbox. |
onLanguageChange
|
Function
|
null
|
A callback function invoked when the user selects a language. Receives the new language code as an argument. |
menuItemSlot
|
Function
|
null
|
A slot function to customize the rendering of menu items. Receives an object with { menuItem, languageCode, languageName } and should return a VNode.
|
Examples
[edit]- In MediaWiki core: 1211707: Use LookupLanguageSelector component in SpecialPageLanguage | https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1211707
- In Translate extension: 1218269: LanguageStatsSpecialPage: Use LookupLanguageSelector | https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Translate/+/1218269
MultiselectLookupLanguageSelector
[edit]A Codex Multiselect Lookup based component that allows users to select multiple languages.
The default list of languages is based on what's supported by MediaWiki. The LanguageNameUtils::getLanguageNames() is used to load the list of languages.
Vue.js usage
[edit]Within a Vue application, import and use the component directly.
const { MultiselectLookupLanguageSelector } = require( 'mediawiki.languageselector' );
// In your Vue component:
// components: { MultiselectLookupLanguageSelector }
<multiselect-lookup-language-selector
v-model:selected="currentLanguages"
:search-api-url="apiUrl"
:selectable-languages="languages"
/>
Props
[edit]| Prop | Type | Default | Description |
|---|---|---|---|
selected
|
Array
|
[]
|
An array of selected language codes (e.g., ['en', 'es']). Using v-model:selected is recommended to handle updates automatically.
|
searchApiUrl
|
String
|
Required | The API URL to use for searching languages (e.g., /w/api.php). required.
|
selectableLanguages
|
Object
|
null
|
An object mapping language codes to language names (e.g., { en: 'English', es: 'Español' }). If not provided, the default list of supported languages is used.
|
debounceDelayMs
|
Number
|
300
|
The debounce delay in milliseconds for the search input. |
menuConfig
|
Object
|
{}
|
Configuration object passed to the underlying Codex multiselect lookup menu. See the Codex Multiselect Lookup documentation |
placeholder
|
String
|
null
|
Placeholder displayed inside the textbox. |
Events
[edit]| Event | Properties | Description |
|---|---|---|
update:selected
|
value (Array)
|
Emitted when the list of selected languages changes. The payload is an array of language codes. This event supports v-model:selected.
|
Examples
[edit]None as of now.
JavaScript Usage
[edit]The module mediawiki.languageselector must be loaded. It exports a factory function, getMultiselectLookupLanguageSelector, which creates a Vue application instance that can be mounted to a DOM element.
mw.loader.using( 'mediawiki.languageselector' ).then( function ( require ) {
const { getMultiselectLookupLanguageSelector } = require( 'mediawiki.languageselector' );
const mySelector = getMultiselectLookupLanguageSelector( {
// Configuration options
selectedLanguages: [ 'en', 'fr' ],
onLanguageChange: function ( langCodes ) {
console.log( 'Selected languages:', langCodes );
}
} );
// Mount the selector to an element on the page
mySelector.mount( '#my-multiselect-container' );
} );
Configuration
[edit]The getMultiselectLookupLanguageSelector function accepts a configuration object with the following properties:
| Property | Type | Default | Description |
|---|---|---|---|
selectedLanguages
|
Array
|
[]
|
The language codes of the initially selected languages (e.g., ['en', 'fr']).
|
selectableLanguages
|
Object
|
null
|
An object mapping language codes to language names (e.g., { en: 'English', es: 'Español' }). If null, a built-in list of supported languages is used.
|
apiUrl
|
string
|
Current wiki API | The URL of the API to use for searching languages (e.g., /w/api.php).
|
menuConfig
|
Object
|
{}
|
Configuration object passed to the underlying Codex multiselect lookup menu. See the Codex Multiselect Lookup documentation for details. |
placeholder
|
String
|
null
|
Placeholder displayed inside the textbox. |
onLanguageChange
|
Function
|
null
|
A callback function invoked when the user selects or deselects a language. Receives the new array of language codes as an argument. |
Examples
[edit]- In Translate extension: 1211663: PageTranslationSpecialPage: Use MultiselectLookupLanguageSelector | https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Translate/+/1211663
Build your own
[edit]The mediawiki.languageselector provides useLanguageSelector that can be used to build a custom language selector. It encapsulates the logic for language searching, filtering, and state management. It is designed to power UI components like the LookupLanguageSelector and MultiselectLookupLanguageSelector.
The default list of languages is based on what's supported by MediaWiki. The LanguageNameUtils::getLanguageNames() is used to load the list of languages.
Usage
[edit]This module exports a function that should be called within the setup() method of a Vue component.
const { useLanguageSelector } = require( 'mediawiki.languageselector' );
const { toRefs } = require( 'vue' );
// Inside a Vue component
setup( props ) {
const { selectableLanguages, selected } = toRefs( props );
const {
search,
searchResults,
selection
} = useLanguageSelector(
selectableLanguages,
selected,
props.searchApiUrl,
300, // debounce delay
false // isMultiple
);
return { search, searchResults, selection };
}
Parameters
[edit]The useLanguageSelector function accepts the following arguments:
| Parameter | Type | Default | Description |
|---|---|---|---|
selectableLanguages
|
Ref<Object>
|
Required | A Vue Ref containing the map of available language codes to names. If the value is null, the composable falls back to a built-in supported languages list. |
selected
|
Ref<String{{!}}Array>
|
Required | A Vue Ref containing the currently selected value(s). If isMultiple is true, this must be an array.
|
searchApiUrl
|
String
|
Required | The URL of the API used to fetch search results. |
debounceDelayMs
|
Number
|
Required | The number of milliseconds to wait before triggering the API search request. |
isMultiple
|
Boolean
|
false
|
Toggle between single-select and multi-select logic. Affects the format of the selection and selectedValues return properties.
|
Return Value
[edit]The function returns an object containing the following properties and methods:
| Property | Type | Description |
|---|---|---|
languages
|
ComputedRef<Object>
|
The complete map of available languages (either the provided selectableLanguages or the default list).
|
search
|
Function
|
A debounced function that accepts a query string. When called, it triggers an API request to filter languages. |
searchResults
|
Ref<Array>
|
An array of language codes that match the current search query. |
searchQuery
|
Ref<String>
|
The current raw search string. |
clearSearchQuery
|
Function
|
Helper function to reset the searchQuery to null.
|
selection
|
ComputedRef<Object{{!}}Array>
|
The current selection formatted for Codex components (containing value and label properties). Returns an Array if isMultiple is true, otherwise a single Object.
|
selectedValues
|
ComputedRef<String{{!}}Array>
|
The raw values of the current selection. Useful for comparing against new inputs. |
isSelectionUpdated
|
Function
|
Accepts a new value (or array of values) and returns true if it differs from the current selectedValues.
|