Jump to content

Module:Langue

Sọn Wikipedia


Module purpose

[jla asisado]

Module:Langue is used to detect, display, and link language variants (for example, Gun (Bénin) and Gun (Gungbe)) in multilingual templates across pages. It helps templates automatically adjust their text or links based on the detected language context — for example, when an article is written in Gungbe versus when it is written in another language.

This module is especially useful for multilingual content and localization of articles, where it ensures consistency and proper language labeling.

Functions

[jla asisado]

The module provides several functions that can be called from templates using `Script error: The function "functionName" does not exist.`.

1. isBJ

[jla asisado]
    • Usage:**

    • Description:**

Checks if the detected language is Gun (Bénin) (based on predefined logic such as site language or page name pattern). It returns the content of the parameter:

  • `yes` – if the detected language is Gun (Bénin)
  • `no` – if it is not
    • Example:**

```wikitext Gun (Gungbe)

Output (depending on language): → Gun (Bénin) or Gun (Gungbe)

=== 2. p2link === Usage: Gun (Bénin)

Description: Creates a clickable tab or link to switch between two language variants of the same page. The override parameter can be used to specify a target page manually.

Example:

Gun (Bénin)

This would create a clickable link for the alternate language tab.

=== 3. alternateLink === Usage: Script error: The function "alternateLink" does not exist.

Description: Used internally by p2link to determine or generate the alternate page name for the language variant.

Example:

Script error: The function "alternateLink" does not exist.

This returns the appropriate alternate page name or link depending on the language.

=== 4. lang === Usage: Gungbe

Description: Returns the code or name of the currently detected language. It can be used to show which language version of the article is being viewed.

Example:

Cet article est écrit en Gun (Gungbe)
This article is written in Gun (Gungbe)

Output: → Cet article est écrit en Gun (Gungbe) → This article is written in Gun (Gungbe)

Example template usage

[jla asisado]

Template:B

[jla asisado]
Gun
(Gungbe)

Cet article est écrit en Gun (Gungbe)
This article is written in Gun (Gungbe)

This template uses Module:Langue to display two horizontally aligned buttons:

Active tab: Shows the detected language (Gun (Bénin) or Gun (Gungbe))

Clickable tab: Provides a link to the other language version


Underneath, it also displays the message:

> Cet article est écrit en Gun (Gungbe) This article is written in Gun (Gungbe)

See also

[jla asisado]

Template:B – the main visual tab template that uses this module

Module:Langue/testcases – optional subpage for module testing

Help:Lua – for learning more about Lua scripting on MediaWiki

Maintenance

[jla asisado]

Author: User:Medaho

Last updated: 2025-10-10


```


local p = {}

-- Letters typical of each variant
local gungbeLetters = {["ẹ"]=true, ["ẹ̀"]=true, ["ẹ́"]=true, ["ọ"]=true, ["ọ̀"]=true, ["ọ́"]=true}
local beninLetters = {["ɖ"]=true, ["ɛ"]=true, ["ɛ̀"]=true, ["ɛ́"]=true, ["ɔ"]=true, ["ɔ̀"]=true, ["ɔ́"]=true, ["ǔ"]=true, ["ě"]=true, ["ǎ"]=true}

-- Helper: check if title includes /guw-bj
local function checkBJ(title)
	return string.find(title:lower(), "/guw%-bj$") ~= nil
end

-- Helper: check for any special letters
local function containsLetter(title, letters)
	for c in mw.ustring.gmatch(title, ".") do
		if letters[c] then return true end
	end
	return false
end

-- Detect which language this page is written in
function p.lang(frame)
	local title = mw.title.getCurrentTitle().fullText
	local isBJ = checkBJ(title)
	local hasGungbe = containsLetter(title, gungbeLetters)
	local hasBenin = containsLetter(title, beninLetters)

	-- Priority: /guw-bj tag overrides everything
	if isBJ then
		return "Bénin"
	elseif hasBenin and not hasGungbe then
		return "Bénin"
	elseif hasGungbe and not hasBenin then
		return "Gungbe"
	else
		return "Gungbe"
	end
end

-- Show yes/no for templates that need it
function p.isBJ(frame)
	local title = mw.title.getCurrentTitle().fullText
	local isBJ = checkBJ(title)
	local hasGungbe = containsLetter(title, gungbeLetters)
	local hasBenin = containsLetter(title, beninLetters)

	if isBJ or (hasBenin and not hasGungbe) then
		return frame.args.yes or ''
	else
		return frame.args.no or ''
	end
end

-- Main: create tab link to the *other* version
function p.p2link(frame)
	local override = frame.args.override or frame.args[1] or ""
	local title = mw.title.getCurrentTitle().fullText
	local isBJ = checkBJ(title)
	local detected = p.lang(frame)

	-- Manual override: show the opposite label
	if override ~= "" then
		local oppositeText = (detected == "Bénin") and "Gun (Gungbe)" or "Gun (Bénin)"
		return "[[" .. override .. "|" .. oppositeText .. "]]"
	end

	-- If current page is Bénin (ends with /guw-bj)
	if isBJ then
		local base = title:gsub("/guw%-bj$", "")
		return "[[" .. base .. "|Gun (Gungbe)]]"  -- always show opposite
	else
		return "[[" .. title .. "/guw-bj|Gun (Bénin)]]"  -- always show opposite
	end
end

return p