ISC-HEI / isc-hei-report

A typst template for reports in the ISC @ HEI curricula
https://isc.hevs.ch
MIT License
6 stars 2 forks source link

Translatable resources #8

Closed pmudry closed 2 weeks ago

pmudry commented 2 weeks ago

It could be a good idea to add some automatic values depending on the language. This could be done by setting the default value to auto and using a dictionary of translatable words.

For example:

#let langs = (
  fr: (
    toc-title: "Table des matières"
  ),
  en: (
    toc-title: "Table of contents"
  )
)

#let i18n(lang, key) = {
  if not lang in langs {
    lang = "fr"
  }
  let keys = langs.at(lang)
  if not key in keys {
    panic("I18n key " + key + "doesn't exist")
  }
  return keys.at(key)
}
#let project(
  toc-title: auto
) = {
  if toc-title == auto {
    toc-title = i18n(language, "toc-title")
  }
}

Originally posted by @LordBaryhobal in https://github.com/ISC-HEI/isc-hei-report/issues/6#issuecomment-2169612206

LordBaryhobal commented 2 weeks ago

Would it make more sense to have a dictionary holding these values, or to store them in a separate JSON file ? From an implementation point of view, it would change much since Typst comes with the builtin json function to parse JSON files

pmudry commented 2 weeks ago

The solution has been implemented with hard-coded values in template in 829e503. Nice suggestion for improvement though !