Skip to content

feat(i18n): add internationalization support (English + German)#136

Open
Marcel-Holzhauer wants to merge 1 commit into
bartneck:mainfrom
Marcel-Holzhauer:feat/i18n
Open

feat(i18n): add internationalization support (English + German)#136
Marcel-Holzhauer wants to merge 1 commit into
bartneck:mainfrom
Marcel-Holzhauer:feat/i18n

Conversation

@Marcel-Holzhauer

Copy link
Copy Markdown

Summary

This PR adds internationalization (i18n) support to swiML. The rendering language is now determined by an optional xml:lang attribute on the <program> element. English and German are supported as initial languages.

Changes

New files

  • i18n/en.xml — English translation file (terms, labels, date format)
  • i18n/de.xml — German translation file

Modified files

  • swiML.xsd — Added optional xml:lang attribute on <program>
  • swiML.xsl — Externalized translations, dynamic alignment calculations, lang attribute on HTML output
  • swiMLPT.xsl — Externalized translations, fixed "Snorkle" typo
  • swimTraining.xsl — Externalized translations
  • README.md — Added xml:lang to usage example, added "Language Support" section

Usage

<!-- German output -->
<program xmlns="https://github.com/bartneck/swiML" xml:lang="de">
    ...
</program>

<!-- English output (default, also when xml:lang is omitted) -->
<program xmlns="https://github.com/bartneck/swiML" xml:lang="en">
    ...
</program>
Design decisions
- Language source: Determined by xml:lang on the source document, not by an XSLT parameter. The author decides the language when writing the program.
- Backward compatible: Existing documents without xml:lang continue to render in English.
- External translation files: Translations are stored in separate XML files (i18n/{lang}.xml) loaded via document(). This keeps the XSLT clean and makes adding new languages trivial.
- Dynamic alignment: The character-width alignment calculations now use string-length() on translated labels instead of hardcoded constants, so alignment works correctly regardless of language.
- Fallback: If a translation key is missing, the raw key name is displayed as a debugging aid.
Adding a new language
Create i18n/{code}.xml following the structure of en.xml or de.xml. No other changes required.
Backward compatibility
- Existing swiML documents are not affected — they render identically to before.
- The XML schema change is purely additive (optional attribute).
- No changes to the Python library.

- Add external translation files (i18n/en.xml, i18n/de.xml)
- Replace inline translation blocks in XSLT with external lookups
- Add xml:lang attribute to schema for language selection
- Fix alignment calculations to work with variable-length translations
- Add lang attribute to HTML output
- Fix Snorkle typo in swiMLPT.xsl
- Update README with language support documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant