Skip to content

Commit

Permalink
chore(languages): Warn when setting a language that has no been loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jun 12, 2024
1 parent 671c5bd commit abd81ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/languages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ loadkit.register("ftl", function (file)
return assert(fluent:add_messages(contents))
end)

local loadonce = {}
SILE.scratch.loaded_languages = {}

SILE.languageSupport = {
languages = {},
loadLanguage = function (language)
language = language or SILE.settings:get("document.language")
language = cldr.locales[language] and language or "und"
if loadonce[language] then
if SILE.scratch.loaded_languages[language] then
return
end
loadonce[language] = true
SILE.scratch.loaded_languages[language] = true
local langresource = string.format("languages.%s", language)
local gotlang, lang = pcall(require, langresource)
if not gotlang then
Expand Down
7 changes: 7 additions & 0 deletions core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ function settings:_init ()
type = "string",
default = "en",
hook = function (language)
if SILE.scratch.loaded_languages and not SILE.scratch.loaded_languages[language] then
SU.warn(([[Setting document.language to '%s', but support for '%s' has not been loaded!
Consider invoking \language[main=%s] which loads language support before
setting it or manually calling SILE.languageSupport.loadLanguage("%s").
]]):format(language, language, language, language))
end
fluent:set_locale(language)
end,
help = "Locale for localized language support",
Expand Down

0 comments on commit abd81ea

Please sign in to comment.