Wikipedia:Lua/Modul/ISO15924/en
ISO15924 – script system according to ISO 15924 and usage in text.
Functions for templates
- getLanguageScript
- Retrieve primary script system code for a language
1 – language code according to ISO 639
- Result: string with script code according to ISO 15924 or
Latn
- isRTL
- Does this code belong to a script written from right to left?
- Result: not empty if right to left
- isScript
- Are all characters of text belonging to a particular script, or neutral?
1 – script code according to ISO 15924
2 – text
- Result: not empty if matching particular script
- isTrans
- Does a transcription system match a particular script?
1 – code of a transcription system
2 – script code according to ISO 15924 or language code according to ISO 639
site – (optional) script code of hosting wiki
- Result: not empty if matching particular transcription system
- scriptName
- Name of a script, hopefully linking on an explaining article
1 – script code according to ISO 15924
2 – (optional) proprietary additional information
lang – (optional) language code for result, default: language of hosting wiki, otherwise English
- Result: empty if invalid or currently unknown
- showScript
- Retrieve script code of first text character
1 – text
- character itself;
Ω → Grek
- Hexcode;
U+03A9 → Grek
- Result: empty if invalid, else script code
- showScripts
- Assign the codepoint and script code to every text character
- Result: text character by character, each with codepoint and script code
- failsafe
- Version ID (local):
2020-03-10
- Optional parameter:
1 – Minimum version or wikidata or ~
{{#invoke:ISO15924|failsafe}} yields 2020-03-10
- With a parameter as ISO date it is compared whether the current module satisfies this version or later.
{{#invoke:ISO15924|failsafe|2001-01-01}} returns: »2020-03-10«
{{#invoke:ISO15924|failsafe|2099-01-01}} returns: »« – (empty), if minimal version condition not matched
- If keyword is
wikidata, result is version ID registered on Wikidata (2020-03-10) or local if not found there.
- If keyword is
~, result is empty if local and Wikidata version are the same: ().
- Returns:
- Empty, if minimal version condition not matched, or
~ and local version is synchronized.
- Version ID if no parameter, or if
wikidata, or local if not found there, or not synchronized.
Examples (test page)
A test page illustrates results on input values.
Survey tables
Survey tables for wikitext pages.
Functions for Lua modules (API)
All functions described above can be used by other modules:
local lucky, ISO15924 = pcall( require, "Module:ISO15924" )
if type( ISO15924 ) == "table" then
ISO15924 = ISO15924.ISO15924()
else
-- In the event of errors, ISO15924 is an error message.
return "<span class=\"error\">" .. ISO15924 .. "</span>"
end
Subsequently there are available:
- ISO15924.getLanguageScript( ask )
- Retrieve primary script system code for a language
ask – language code according to ISO 639
- returns: string with script code according to ISO 15924 or
Latn
- ISO15924.isRTL( ask )
- Does this code belong to a script written from right to left?
- returns: boolean
- ISO15924.isScript( assume, analyse )
- Are all characters of text belonging to a particular script, or neutral?
assume – script code according to ISO 15924
analyse – text as string or codepoint or table of single characters
- returns: boolean and table
- matching
- table of single characters in
analyse
- ISO15924.isTrans( ask, assign, about )
- Does a transcription system match a particular script?
ask – code of a transcription system
assign – script code according to ISO 15924 or language code according to ISO 639
about – (optional) script code of hosting wiki
- returns: boolean
- ISO15924.scriptName( assigned, alien, add )
- Name of a script, hopefully linking on an explaining article
assigned – script code according to ISO 15924
alien – (optional) proprietary additional information
add – (optional) language code for result, default: language of hosting wiki, otherwise English
- returns: string, empty if invalid or currently unknown
- ISO15924.showScript( analyse )
- Retrieve script code of first text character
analyse – text as string or codepoint or table of single characters
- returns: script code, or false
- ISO15924.showScripts( analyse )
- Assign the codepoint and script code to every text character
analyse – text as string or codepoint or table of single characters
- returns: string, character by character, each with codepoint and script code
- ISO15924.testScripts( assume, analyse )
- How many text characters of text are belonging to a particular script?
assume – script code according to ISO 15924
analyse – text as string or codepoint or table of single characters
- returns: two numbers
- number of explicitly matching characters
- number of violating characters
- ISO15924.failsafe( atleast )
- Versioning interface
- atleast
optional
nil or minimum version or wikidata or ~ for synchronisation
- returns: Version ID as string or
false
Internal sub modules
loadData
The global data will be converted each into Lua table, which is available by mw.loadData() once per rendered page.
There are two access modes:
- Module:ISO15924/commons
- Live generation from global data on Commons; might need a purge after change.
- Module:ISO15924/codes
- Same information, but frozen snapshot.
- Better performance.
Data structure:
- Payload are components with one table each as assignment:
cjk – boolean, if CJK
iso639script – sequence table with any number of string items – script systems usually matching this language
rtl – boolean, if right to left
trans – sequence table with any number of string items – transcription systems dedicated to script or language
unicodes – sequence table with Unicode ranges applicable for a script system (table of two numbers as codepoints)
reverse – sequence table with two numbers as codepoints and table with any number of string items – script systems
failsafe – string with version ID
last – boolean, true if static Lua code updated with Wikidata
/maintain
Internal – functions for generation of derived data and maintainance etc.
Project configuration
By Module:ISO15924/config the local project may be configured optionally.
Returns table with components:
- live
true – Use commons → commons:Data:
- Default: Snapshot
- tmplLang
- Pattern for templates in local project to show a particular language name and link to explaining page
- table with components:
title – unique name of template
namePat – pattern for name of template, with %s for code according to ISO 639
param – parameter name, for code according to ISO 639
- Examples:
- enwiki →
{ namePat = "lang-%s" }
- dewiki →
{ namePat = "%sS" }
Installation on other WMF projects
Follow the steps:
- Copy main module
Module:ISO15924 into your project.
- If possible keep the name
ISO15924.
- If another name is required due to conflict or naming convention or non-latin script then choose a different one.
- Register this module at d:Q71584769.
- Copy at least one of the following sub modules, and keep the chosen root name:
- If
/commons is chosen, in project configuration live switch is needed.
- If script names shall be shown
/translate needs to be copied and extended to local language.
- Translations might be passed back to upstream (here).
/pages are needed for linking with articles.
- In future Wikidata lexems and items may be exploited as fallback.
- If wikitext pages with survey tables are desired
/table is necessary.
- Ready.
- Consider translation of doc page.
Usage
General library; no limitations.