• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 10728217744

05 Sep 2024 09:07PM UTC coverage: 58.013% (-4.5%) from 62.464%
10728217744

push

github

alerque
refactor(cli): Satiate clippy's new "never type fallback" lint

New in Rust 1.81.0, scheduled to be an error in edition 2024:

https://github.com/rust-lang/rust/issues/123748

It looks like mlua v0.10 won't need this workaround:

https://github.com/mlua-rs/mlua/commit/3641c9895

10103 of 17415 relevant lines covered (58.01%)

1419.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.23
/core/languages.lua
1
--- SILE language class.
2
-- @interfaces languages
3

4
local loadkit = require("loadkit")
80✔
5
local cldr = require("cldr")
80✔
6

7
loadkit.register("ftl", function (file)
160✔
8
   local contents = assert(file:read("*a"))
90✔
9
   file:close()
90✔
10
   return assert(fluent:add_messages(contents))
180✔
11
end)
12

13
SILE.scratch.loaded_languages = {}
80✔
14

15
SILE.languageSupport = {
80✔
16
   languages = {},
80✔
17
   loadLanguage = function (language)
18
      language = language or SILE.settings:get("document.language")
2,325✔
19
      language = cldr.locales[language] and language or "und"
2,325✔
20
      if SILE.scratch.loaded_languages[language] then
2,325✔
21
         return
2,235✔
22
      end
23
      SILE.scratch.loaded_languages[language] = true
90✔
24
      local langresource = string.format("languages.%s", language)
90✔
25
      local gotlang, lang = pcall(require, langresource)
90✔
26
      if not gotlang then
90✔
27
         SU.warn(
2✔
28
            ("Unable to load language feature support (e.g. hyphenation rules) for %s: %s"):format(
2✔
29
               language,
1✔
30
               lang:gsub(":.*", "")
1✔
31
            )
32
         )
33
      end
34
      local ftlresource = string.format("i18n.%s", language)
90✔
35
      SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
90✔
36
      -- This needs to be set so that we load localizations into the right bundle,
37
      -- but this breaks the sync enabled by the hook in the document.language
38
      -- setting, so we want to set it back when we're done.
39
      local original_language = fluent:get_locale()
90✔
40
      fluent:set_locale(language)
90✔
41
      local gotftl, ftl = pcall(require, ftlresource)
90✔
42
      if not gotftl then
90✔
43
         SU.warn(
×
44
            ("Unable to load localized strings (e.g. table of contents header text) for %s: %s"):format(
×
45
               language,
46
               ftl:gsub(":.*", "")
×
47
            )
48
         )
49
      end
50
      if type(lang) == "table" and lang.init then
90✔
51
         lang.init()
1✔
52
      end
53
      fluent:set_locale(original_language)
90✔
54
   end,
55
}
80✔
56

57
SILE.registerCommand("language", function (options, content)
160✔
58
   local main = SU.required(options, "main", "language setting")
1✔
59
   SILE.languageSupport.loadLanguage(main)
1✔
60
   if content[1] then
1✔
61
      SILE.settings:temporarily(function ()
×
62
         SILE.settings:set("document.language", main)
×
63
         SILE.process(content)
×
64
      end)
65
   else
66
      SILE.settings:set("document.language", main)
1✔
67
   end
68
end, nil, nil, true)
81✔
69

70
SILE.registerCommand("fluent", function (options, content)
160✔
71
   local key = content[1]
×
72
   local locale = options.locale or SILE.settings:get("document.language")
×
73
   local original_locale = fluent:get_locale()
×
74
   fluent:set_locale(locale)
×
75
   SU.debug("fluent", "Looking for", key, "in", locale)
×
76
   local entry
77
   if key then
×
78
      entry = fluent:get_message(key)
×
79
   else
80
      SU.warn("Fluent localization function called without passing a valid message id")
×
81
   end
82
   local message
83
   if entry then
×
84
      message = entry:format(options)
×
85
   else
86
      SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
87
      fluent:set_locale("und")
×
88
      entry = fluent:get_message(key)
×
89
      if entry then
×
90
         message = entry:format(options)
×
91
      end
92
   end
93
   fluent:set_locale(original_locale)
×
94
   SILE.processString(("<sile>%s</sile>"):format(message), "xml")
×
95
end, nil, nil, true)
80✔
96

97
SILE.registerCommand("ftl", function (options, content)
160✔
98
   local original_locale = fluent:get_locale()
×
99
   local locale = options.locale or SILE.settings:get("document.language")
×
100
   SU.debug("fluent", "Loading message(s) into locale", locale)
×
101
   fluent:set_locale(locale)
×
102
   if options.src then
×
103
      fluent:load_file(options.src, locale)
×
104
   elseif SU.ast.hasContent(content) then
×
105
      local input = content[1]
×
106
      fluent:add_messages(input, locale)
×
107
   end
108
   fluent:set_locale(original_locale)
×
109
end, nil, nil, true)
80✔
110

111
require("languages.unicode")
80✔
112

113
-- The following languages neither have hyphenation nor specific
114
-- language support at present. This code is here to suppress warnings.
115
SILE.hyphenator.languages.ar = { patterns = {} }
80✔
116
SILE.hyphenator.languages.bo = { patterns = {} }
80✔
117
SILE.hyphenator.languages.sd = { patterns = {} }
80✔
118
SILE.hyphenator.languages.ur = { patterns = {} }
80✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc