Module:I18n/doc
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module depends on the following other modules: |
| Description | Library for message storage in Lua datastores. |
|---|---|
| Author(s) |
|
| Status | Beta |
| Updated | May 5, 2025 (13 months ago) |
| Dependencies | |
| Using code by | Cqm |
I18n library for message storage in Lua datastores. The module is designed to enable message separation from modules & templates. It has support for handling language fallbacks. This module is a Lua port of wikia:dev:I18n-js and i18n modules that can be loaded by it are editable through wikia:dev:I18nEdit.
On Wikimedia projects, i18n messages are editable through Data:i18n/ subpages on Wikimedia Commons.
Documentation
Package items
i18n.getMsg( frame )(function)- Localized message getter by key. Can be used to fetch messages in a specific language code through
uselangparameter. Extra numbered parameters can be supplied for substitution into the datastore message. - Parameters:
- Error: 'missing arguments in i18n.getMsg' (line 271)
- Returns: I18n message in localised language. (string)
i18n.loadMessages( ... )(function)- I18n message datastore loader.
- Parameter:
...ROOTPAGENAME/path for target i18n submodules. (string) - Error: 'no source supplied to i18n.loadMessages' (line 322)
- Returns: I18n datastore instance. (table)
- Usage:
require('Module:I18n').loadMessages('1', '2') i18n.getLang( )(function)- Language code getter. Can validate a template's language code through
uselangparameter. - Returns: Language code. (string)
i18n.loadI18n( name, i18n_arg )(function)- Given an i18n table instantiates the values (deprecated)
- Parameters:
i18n.loadI18nFrame( name, i18n_arg )(function)- Loads an i18n for a specific frame (deprecated)
- Parameters:
i18n.main( frame )(function)- Wrapper for the module.
- Parameter:
frameFrame invocation object. (table) - Returns: Module output in template context. (string)
- Usage:
{{#invoke:i18n|main}} _i18n.isWikitext( msg )(function)- Checks whether a message contains unprocessed wikitext. Used to optimise message getter by not preprocessing pure text.
- Parameter:
msgMessage to check. (string) - Returns: Whether the message contains wikitext. (boolean)
Data
I18n datastore class. This is used to control language translation and access to individual messages. The datastore instance provides language and message getter-setter methods, which can be used to internationalize Lua modules. The language methods (any ending in Lang) are all chainable.
Data:msg( opts, ... )(function)- Datastore message getter utility. This method returns localized messages from the datastore corresponding to a
key. These messages may have$nparameters, which can be replaced by optional argument strings supplied by themsgcall. - This function supports named arguments. The named argument syntax is more versatile despite its verbosity; it can be used to select message language & source(s).
- Parameters:
- Error: 'missing arguments in Data:msg' (line 115)
- Returns: Localised datastore message or
'<key>'. (string) - Usage:
ds:msg{ key = 'message-name', lang = '', args = {...}, sources = {} }
ds:msg('message-name', ...)
Data:parameter( parameter, args )(function)- Datastore template parameter getter utility. This method, given a table of arguments, tries to find a parameter's localized name in the datastore and returns its value, or nil if not present.
- This method always uses the wiki's content language.
- Parameters:
- Error: 'missing arguments in Data:parameter' (line 176)
- Returns: Parameter's value or nil if not present (string|nil)
Data:fromSource( ... )(function)- Datastore temporary source setter to a specificed subset of datastores. By default, messages are fetched from the datastore in the same order of priority as
i18n.loadMessages. - Parameter:
...Source name(s) to use. (string) - Returns: Datastore instance. (Data)
Data:getLang( )(function)- Datastore default language getter.
- Returns: Default language to serve datastore messages in. (string)
Data:useUserLang( )(function)- Datastore language setter to
wgUserLanguage. - Returns: Datastore instance. (Data)
- Note: Scribunto only registers
wgUserLanguagewhen an invocation is at the top of the call stack. Data:useContentLang( )(function)- Datastore language setter to
wgContentLanguage. - Returns: Datastore instance. (Data)
Data:useLang( code )(function)- Datastore language setter to specificed language.
- Parameter:
codeLanguage code to use. (string) - Returns: Datastore instance. (Data)
Data:inUserLang( )(function)- Temporary datastore language setter to
wgUserLanguage. The datastore language reverts to the default language in the nextData:msgcall. - Returns: Datastore instance. (Data)
Data:inContentLang( )(function)- Temporary datastore language setter to
wgContentLanguage. Only affects the nextData:msgcall. - Returns: Datastore instance. (Data)
Data:inLang( code )(function)- Temporary datastore language setter to a specificed language. Only affects the next
Data:msgcall. - Parameter:
codeLanguage code to use. (string) - Returns: Datastore instance. (Data)
See also
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.