Skip to content

Commit

Permalink
feat(i18n): Fallback to messages from 'und' language if no localized
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Aug 4, 2022
1 parent fde1d35 commit 0314e33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class.packages = {}

function class:_init (options)
if self == options then options = {} end
SILE.languageSupport.loadLanguage('und') -- preload for unlocalized fallbacks
self:declareOptions()
self:registerRawHandlers()
self:registerCommands()
Expand Down
6 changes: 6 additions & 0 deletions core/languages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ SILE.registerCommand("fluent", function (options, content)
message = entry:format(options)
else
SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
fluent:set_locale('und')
entry = fluent:get_message(key)
if entry then
message = entry:format(options)
end
fluent:set_locale(locale)
end
SILE.processString(("<sile>%s</sile>"):format(message), "xml")
end, nil, nil, true)
Expand Down
2 changes: 2 additions & 0 deletions i18n/und.ftl
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
hello = Namárië <em>{ $name }</em>!
tableofcontents-not-generated = Rerun SILE to process the table of contents!

0 comments on commit 0314e33

Please sign in to comment.