Jump to content

Template:Catllengua

Unchecked
From Wikipedia

Module:Catllengua

-- Module:Catllengua
local M = {}

-- Known aliases mapping (extend as needed)
local alias = {
  en = "English", ["eng"]="English", ["english"]="English",
  es = "Spanish", ["spa"]="Spanish", ["español"]="Spanish", ["spanish"]="Spanish", ["castellano"]="Spanish",
  fr = "French",  ["fra"]="French", ["fre"]="French", ["français"]="French", ["french"]="French",
  de = "German",  ["ger"]="German", ["deu"]="German", ["german"]="German", ["deutsch"]="German",
  zh = "Chinese", ["zho"]="Chinese", ["chi"]="Chinese", ["中文"]="Chinese", ["chinese"]="Chinese",
  ja = "Japanese", ["jpn"]="Japanese", ["日本語"]="Japanese", ["japanese"]="Japanese",
  ko = "Korean", ["kor"]="Korean", ["한국어"]="Korean", ["korean"]="Korean",
  it = "Italian", ["ita"]="Italian", ["italiano"]="Italian", ["italian"]="Italian",
  pt = "Portuguese", ["por"]="Portuguese", ["português"]="Portuguese", ["portuguese"]="Portuguese",
  ru = "Russian", ["rus"]="Russian", ["русский"]="Russian", ["russian"]="Russian",
}

local function trim(s)
  return (tostring(s or ""):gsub("^%s+",""):gsub("%s+$",""))
end

local function split(list)
  list = tostring(list or "")
  list = list:gsub(",", ";")
  local t = {}
  for part in list:gmatch("([^;]+)") do
    table.insert(t, trim(part))
  end
  return t
end

local function normName(token)
  local key = mw.ustring.lower(trim(token))
  return alias[key] or (token and mw.text.trim(token)) or ""
end

function M.normalize(frame)
  local list = frame.args.list or ""
  local t = split(list)
  -- Recompose as semicolon-separated normalized tokens (original tokens preserved for display)
  -- Here we just return the cleaned list to keep commas uniform
  return table.concat(t, ";")
end

function M.getBadge(frame)
  local list = frame.args.list or ""
  local badge = frame.args.badge
  local t = split(list)
  local names = {}
  for _, tok in ipairs(t) do
    local name = normName(tok)
    if name ~= "" then table.insert(names, name) end
  end
  local text = badge and trim(badge) ~= "" and badge or (#names == 1 and names[1] or table.concat(names, " · "))
  return text
end

function M.emitCats(frame)
  local list = frame.args.list or ""
  local scope = frame.args.scope or "Articles"
  local prefix = frame.args.prefix or "Category:Language-related "
  local hidden = frame.args.hidden == "yes"

  local t = split(list)
  local buf = {}
  for _, tok in ipairs(t) do
    local name = normName(tok)
    if name ~= "" then
      local cat = string.format("%s%s (%s)", prefix, name, scope)
      -- Hidden cats are site-config dependent; we just output normal cats.
      table.insert(buf, string.format("[[%s]]", cat))
    end
  end
  return table.concat(buf, "\n")
end

return M

Template documentation

[edit]

Template sandbox and testcases for TEMPLATE_NAME

[edit]

Overview

[edit]

This page provides a clean workflow to safely edit and validate TEMPLATE_NAME:

  • Sandbox: Template:TEMPLATE_NAME/sandbox — a working copy where you make changes.
  • Testcases: Template:TEMPLATE_NAME/testcases — inputs that exercise typical and edge cases.
  • Live: Template:TEMPLATE_NAME — the production version. Do not edit directly without review.

Use this page to:

  • Preview sandbox output against fixed testcases without touching the live template.
  • Compare actual vs expected output for each testcase.
  • Track recent changes and invite reviewers.
[edit]

How to test

[edit]

1. Edit the sandbox at Template:TEMPLATE_NAME/sandbox. 2. Open this test page and click “Show preview” to render the sandbox with inputs below. 3. Verify each testcase: Does the “Actual output” match the “Expected output”? 4. If all pass, consider copying sandbox to live using an edit summary like:

  “Sync from /sandbox: passes all /testcases as of YYYY-MM-DD.”

Previewing tips

[edit]
  • Use “Preview page with this template” gadget or the built-in preview.
  • Check parser output in different skins and mobile view.
  • Validate accessibility: headings order, link text, ARIA where applicable.
  • Internationalization: test with non-ASCII parameters and RTL where relevant.

Test harness

[edit]

The following sections render the sandbox template against curated inputs. Each testcase shows:

  • Parameters passed to the template
  • Expected output (as plain wikitext target)
  • Actual output (rendered via sandbox transclusion)

Testcase A: Minimal invocation

[edit]

Parameters: {{TEMPLATE_NAME}}

Expected output: [Minimal successful output with defaults: e.g., a neutral message or basic box]

Actual output (sandbox):

Character and language test sandbox

This sandbox is used to test how Template:TEMPLATE NAME behaves with special characters (such as Greek letters) and language-specific spans.

Basic examples

[edit]
  • Greek letter (direct character): α
  • Greek letter (HTML entity): γ
  • German span example: A

Within the template

[edit]

Below are example calls of the template using these characters as parameters.

{{TEMPLATE NAME | title = Greek test: α γ | summary = Demonstrating Greek letters: α, β, γ, and entities like γ. | attr1 = Direct Greek: α β γ δ | attr2 = Entity Greek: α β γ δ | attr3 = German label: <span lang="de">A</span>, English label: A }}

Preview the page to check if:

  • Greek characters (α, β, γ, δ) display correctly.
  • HTML entities (α, β, γ, δ) render as the expected symbols.
  • The A is kept as a German-language span and does not break the layout.

Notes

[edit]
  • Use this sandbox to experiment with different scripts (Greek, Cyrillic, etc.).
  • Test right-to-left scripts by adding spans with lang="ar" or lang="he".
  • If the template trims or escapes some of these, adjust the template code accordingly.

Testcase B: Common parameters

[edit]

Parameters: {{TEMPLATE_NAME | param1 = Alpha | param2 = Beta | flag = yes }}

Expected output: [Example: shows "Alpha" and "Beta" in designated slots; flag toggles enhanced styling]

Actual output (sandbox):

Character and language test sandbox

This sandbox is used to test how Template:TEMPLATE NAME behaves with special characters (such as Greek letters) and language-specific spans.

Basic examples

[edit]
  • Greek letter (direct character): α
  • Greek letter (HTML entity): γ
  • German span example: A

Within the template

[edit]

Below are example calls of the template using these characters as parameters.

{{TEMPLATE NAME | title = Greek test: α γ | summary = Demonstrating Greek letters: α, β, γ, and entities like γ. | attr1 = Direct Greek: α β γ δ | attr2 = Entity Greek: α β γ δ | attr3 = German label: <span lang="de">A</span>, English label: A }}

Preview the page to check if:

  • Greek characters (α, β, γ, δ) display correctly.
  • HTML entities (α, β, γ, δ) render as the expected symbols.
  • The A is kept as a German-language span and does not break the layout.

Notes

[edit]
  • Use this sandbox to experiment with different scripts (Greek, Cyrillic, etc.).
  • Test right-to-left scripts by adding spans with lang="ar" or lang="he".
  • If the template trims or escapes some of these, adjust the template code accordingly.

Testcase C: Edge values and escaping

[edit]

Parameters: {{TEMPLATE_NAME | param1 = [[Linked target|Visible text]] | param2 = {{subst:CURRENTTIMESTAMP}} | raw = <code><span class="x">escaped</span></code> }}

Expected output: [Links render correctly; timestamp subst is literal in expected; raw shows escaped markup]

Actual output (sandbox):

Character and language test sandbox

This sandbox is used to test how Template:TEMPLATE NAME behaves with special characters (such as Greek letters) and language-specific spans.

Basic examples

[edit]
  • Greek letter (direct character): α
  • Greek letter (HTML entity): γ
  • German span example: A

Within the template

[edit]

Below are example calls of the template using these characters as parameters.

{{TEMPLATE NAME | title = Greek test: α γ | summary = Demonstrating Greek letters: α, β, γ, and entities like γ. | attr1 = Direct Greek: α β γ δ | attr2 = Entity Greek: α β γ δ | attr3 = German label: <span lang="de">A</span>, English label: A }}

Preview the page to check if:

  • Greek characters (α, β, γ, δ) display correctly.
  • HTML entities (α, β, γ, δ) render as the expected symbols.
  • The A is kept as a German-language span and does not break the layout.

Notes

[edit]
  • Use this sandbox to experiment with different scripts (Greek, Cyrillic, etc.).
  • Test right-to-left scripts by adding spans with lang="ar" or lang="he".
  • If the template trims or escapes some of these, adjust the template code accordingly.

Testcase D: Internationalization (i18n)

[edit]

Parameters: {{TEMPLATE_NAME | lang = ja | text = こんにちは世界 }}

Expected output: [Text displays correctly for non-ASCII; applies lang attribute or rtl/ltr where applicable]

Actual output (sandbox):

Character and language test sandbox

This sandbox is used to test how Template:TEMPLATE NAME behaves with special characters (such as Greek letters) and language-specific spans.

Basic examples

[edit]
  • Greek letter (direct character): α
  • Greek letter (HTML entity): γ
  • German span example: A

Within the template

[edit]

Below are example calls of the template using these characters as parameters.

{{TEMPLATE NAME | title = Greek test: α γ | summary = Demonstrating Greek letters: α, β, γ, and entities like γ. | attr1 = Direct Greek: α β γ δ | attr2 = Entity Greek: α β γ δ | attr3 = German label: <span lang="de">A</span>, English label: A }}

Preview the page to check if:

  • Greek characters (α, β, γ, δ) display correctly.
  • HTML entities (α, β, γ, δ) render as the expected symbols.
  • The A is kept as a German-language span and does not break the layout.

Notes

[edit]
  • Use this sandbox to experiment with different scripts (Greek, Cyrillic, etc.).
  • Test right-to-left scripts by adding spans with lang="ar" or lang="he".
  • If the template trims or escapes some of these, adjust the template code accordingly.

Testcase E: Error handling

[edit]

Parameters: {{TEMPLATE_NAME | param1 = | required = <!-- intentionally omitted --> }}

Expected output: [Shows a gentle error or maintenance category; does not break page layout]

Actual output (sandbox):

Character and language test sandbox

This sandbox is used to test how Template:TEMPLATE NAME behaves with special characters (such as Greek letters) and language-specific spans.

Basic examples

[edit]
  • Greek letter (direct character): α
  • Greek letter (HTML entity): γ
  • German span example: A

Within the template

[edit]

Below are example calls of the template using these characters as parameters.

{{TEMPLATE NAME | title = Greek test: α γ | summary = Demonstrating Greek letters: α, β, γ, and entities like γ. | attr1 = Direct Greek: α β γ δ | attr2 = Entity Greek: α β γ δ | attr3 = German label: <span lang="de">A</span>, English label: A }}

Preview the page to check if:

  • Greek characters (α, β, γ, δ) display correctly.
  • HTML entities (α, β, γ, δ) render as the expected symbols.
  • The A is kept as a German-language span and does not break the layout.

Notes

[edit]
  • Use this sandbox to experiment with different scripts (Greek, Cyrillic, etc.).
  • Test right-to-left scripts by adding spans with lang="ar" or lang="he".
  • If the template trims or escapes some of these, adjust the template code accordingly.

Maintenance

[edit]
  • Add new testcases when introducing features or fixing bugs.
  • Keep “Expected output” updated; include rationale in edit summaries.
  • When deprecating parameters, add tests demonstrating legacy behavior and warnings.

Categories

[edit]

Copy-paste skeletons

[edit]

Below are ready-to-use skeletons for the sandbox and testcases subpages.

Skeleton: Template:TEMPLATE_NAME/sandbox

[edit]

<!-- Sandbox for TEMPLATE_NAME --> <!-- Copy the entire template source here; edit safely. --> {{#if:{{{required|}}} | <!-- normal output --> <div class="tmpl"> <b>{{{param1|}}}</b> · <i>{{{param2|}}}</i> {{#if:{{{flag|}}}|<span class="flag">✓</span>|}} {{#if:{{{raw|}}}|<span class="raw">{{{raw}}}</span>|}} </div> | <!-- error / missing required --> <span class="error">TEMPLATE_NAME: missing required parameter</span> [[Category:Pages with TEMPLATE_NAME errors]] }}

Skeleton: Template:TEMPLATE_NAME/testcases

[edit]

<!-- Testcases for TEMPLATE_NAME; render against /sandbox --> ; Minimal : {{TEMPLATE_NAME/sandbox}} ; Common params : {{TEMPLATE_NAME/sandbox | param1 = Alpha | param2 = Beta | flag = yes }} ; Edge and escaping : {{TEMPLATE_NAME/sandbox | param1 = [[Linked target|Visible text]] | param2 = 20250101T000000Z | raw = <code><span class="x">escaped</span></code> }} ; I18n : {{TEMPLATE_NAME/sandbox | lang = ja | text = こんにちは世界 }} ; Error handling : {{TEMPLATE_NAME/sandbox | required = }}

Review checklist

[edit]
  • Output is stable across re-parses; no expensive parser functions without need.
  • No unexpected categorization in mainspace; errors go to maintenance cats.
  • Template is documented at Template:TEMPLATE_NAME/doc with parameters, examples, and tracking.
  • Style is minimal; avoid inline CSS unless necessary; consider using existing module or template styles.
This box: view  talk  edit

Template:Catllengua helps categorize pages by language. Provide one or more language codes/names; the template emits appropriate Language-related categories and optionally displays an inline badge summarizing the languages involved.

Purpose

[edit]
  • Group pages by language context (e.g., articles discussing Spanish phonology or French literature).
  • Support maintenance and WikiProject workflows by consistent categorization naming.
  • Offer a compact badge for readers indicating language scope.

Usage

[edit]

Basic (single language):

{{Catllengua|lang=Spanish}}

Multiple languages:

{{Catllengua|langs=en, fr, de}}

Inline badge:

{{Catllengua|langs=zh, ja|show=yes}}

Custom badge text:

{{Catllengua|langs=pt, es|show=yes|badge=Iberian languages}}

Suppress categorization (preview/debug):

{{Catllengua|lang=English|nocat=yes|show=yes}}

Scope variants:

{{Catllengua|lang=Italian|scope=Templates}}
{{Catllengua|lang=German|scope=Project pages}}

Category prefix override:

{{Catllengua|lang=Korean|catprefix=Category:Topic by language }}

Parameters

[edit]
lang
Single language code or name (e.g., en, English, español).
langs
Comma-separated list of languages (overrides lang).
show
yes/true/1 to display a small inline badge.
badge
Custom badge text; defaults to resolved language names.
hidden
Reserved flag to indicate hidden maintenance categories (actual hiding depends on site config).
scope
A suffix shown in parentheses to distinguish organizational scope, default Articles.
catprefix
Category namespace/prefix; default Category:Language-related .
nocat
Suppress category emission; useful in documentation or tests.

Category naming

[edit]

By default, this template outputs per-language categories named:

Category:Language-related English (Articles)
Category:Language-related French (Articles)
...

Adjust with scope or catprefix to match local conventions.

Aliases supported

[edit]

The Lua module maps common codes and endonyms to canonical names:

en → English; es → Spanish; fr → French; de → German; zh → Chinese; ja → Japanese; ko → Korean; it → Italian; pt → Portuguese; ru → Russian

Extend the table in Module:Catllengua for more languages and variants.

Best practices

[edit]
  • Use IETF language codes (en, es, fr) or well-known names.
  • Keep catprefix aligned with existing category trees.
  • Provide scope to separate article vs template/project categories.
  • For large multi-language pages, include only languages central to the topic, not incidental mentions.

Examples

[edit]
  • Single language with badge:
{{Catllengua|lang=English|show=yes}}
  • Multi-language categorization only:
{{Catllengua|langs=Arabic, Hebrew}}
  • Custom tree:
{{Catllengua|langs=Hindi|catprefix=Category:Topics by language }}

See also

[edit]