Skip to content

Use mul as multilingual text fallback - #71

Merged
dahlia merged 1 commit into
mainfrom
mul-fallback
Aug 4, 2026
Merged

dahlia merged 1 commit into
mainfrom
mul-fallback

Conversation

@dahlia

@dahlia dahlia commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Wikidata uses the mul language code for a default label that applies when a language-specific label is absent. MultilingualText.__str__() previously skipped that default when no English label existed and returned the final entry in the mapping instead. This made the result depend on JSON insertion order. For Q187560, for example, mul contains Scheme, but the later Kurdish label was rendered.

The lookup in wikidata/multilingual.py keeps the existing English-first behavior. It checks an exact en value, accepts both Babel-era underscore variants such as en_US and Wikidata-style hyphen variants such as en-gb, and then consults mul. The previous last-entry fallback remains for mappings without any of those values. This gives the Wikidata default a defined place without changing the result when an English value is available.

The regression cases in tests/multilingual_test.py put mul before and after an unrelated label to make the result independent of insertion order. Separate cases pin each precedence boundary and retain the old fallback for mappings that have neither an English value nor mul.

Closes #70.

Prefer Wikidata's mul default value when no English label or English
locale variant is available.  Preserve the existing arbitrary fallback
for multilingual mappings without either value, and cover the selection
order with regression tests.

Closes #70

Assisted-by: Codex:gpt-5.6-sol
@dahlia
dahlia requested a lite review from Copilot August 4, 2026 18:04
@dahlia dahlia self-assigned this Aug 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes MultilingualText.__str__() to use Wikidata’s mul language code as a stable fallback when no English label is available, eliminating prior dependence on JSON/dict insertion order.

Changes:

  • Updated MultilingualText.__str__() to prefer en, then English variants (en_… / en-…), then mul, and only then fall back to the final mapping value.
  • Added regression tests to pin the precedence rules and ensure results are independent of insertion order around mul.
  • Documented the behavior change in the changelog for the upcoming release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
wikidata/multilingual.py Implements mul fallback after English/English-variant checks, preserving legacy last-entry fallback otherwise.
tests/multilingual_test.py Adds tests covering en vs variants vs mul precedence and insertion-order independence.
docs/changes.rst Records the behavior change for release notes, referencing issue #70.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dahlia
dahlia merged commit 435874e into main Aug 4, 2026
21 of 28 checks passed
@dahlia
dahlia deleted the mul-fallback branch August 4, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: return 'mul' valule if 'en' is not set in MultilingualText.__str__

2 participants