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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

89.33
/core/languages.lua
1
local loadkit = require("loadkit")
181✔
2
local cldr = require("cldr")
181✔
3

4
loadkit.register("ftl", function (file)
362✔
5
   local contents = assert(file:read("*a"))
388✔
6
   file:close()
388✔
7
   return assert(fluent:add_messages(contents))
776✔
8
end)
9

10
local loadonce = {}
181✔
11

12
SILE.languageSupport = {
181✔
13
   languages = {},
181✔
14
   loadLanguage = function (language)
15
      language = language or SILE.settings:get("document.language")
12,233✔
16
      language = cldr.locales[language] and language or "und"
12,233✔
17
      if loadonce[language] then
12,233✔
18
         return
11,843✔
19
      end
20
      loadonce[language] = true
390✔
21
      local langresource = string.format("languages.%s", language)
390✔
22
      local gotlang, lang = pcall(require, langresource)
390✔
23
      if not gotlang then
390✔
24
         SU.warn(
18✔
25
            ("Unable to load language feature support (e.g. hyphenation rules) for %s: %s"):format(
18✔
26
               language,
9✔
27
               lang:gsub(":.*", "")
9✔
28
            )
29
         )
30
      end
31
      local ftlresource = string.format("i18n.%s", language)
390✔
32
      SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
390✔
33
      fluent:set_locale(language)
390✔
34
      local gotftl, ftl = pcall(require, ftlresource)
390✔
35
      if not gotftl then
390✔
36
         SU.warn(
4✔
37
            ("Unable to load localized strings (e.g. table of contents header text) for %s: %s"):format(
4✔
38
               language,
2✔
39
               ftl:gsub(":.*", "")
2✔
40
            )
41
         )
42
      end
43
      if type(lang) == "table" and lang.init then
390✔
44
         lang.init()
11✔
45
      end
46
   end,
47
}
181✔
48

49
SILE.registerCommand("language", function (options, content)
362✔
50
   local main = SU.required(options, "main", "language setting")
24✔
51
   SILE.languageSupport.loadLanguage(main)
24✔
52
   if content[1] then
24✔
53
      SILE.settings:temporarily(function ()
2✔
54
         SILE.settings:set("document.language", main)
1✔
55
         SILE.process(content)
1✔
56
      end)
57
   else
58
      SILE.settings:set("document.language", main)
23✔
59
   end
60
end, nil, nil, true)
205✔
61

62
SILE.registerCommand("fluent", function (options, content)
362✔
63
   local key = content[1]
7✔
64
   local locale = options.locale or SILE.settings:get("document.language")
7✔
65
   SU.debug("fluent", "Looking for", key, "in", locale)
7✔
66
   local entry
67
   if key then
7✔
68
      fluent:set_locale(locale)
7✔
69
      entry = fluent:get_message(key)
14✔
70
   else
NEW
71
      SU.warn("Fluent localization function called without passing a valid message id")
×
72
   end
73
   local message
74
   if entry then
7✔
75
      message = entry:format(options)
14✔
76
   else
NEW
77
      SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
NEW
78
      fluent:set_locale("und")
×
NEW
79
      entry = fluent:get_message(key)
×
NEW
80
      if entry then
×
NEW
81
         message = entry:format(options)
×
82
      end
NEW
83
      fluent:set_locale(locale)
×
84
   end
85
   SILE.processString(("<sile>%s</sile>"):format(message), "xml")
7✔
86
end, nil, nil, true)
188✔
87

88
SILE.registerCommand("ftl", function (options, content)
362✔
89
   local locale = options.locale or SILE.settings:get("document.language")
1✔
90
   SU.debug("fluent", "Loading message(s) into locale", locale)
1✔
91
   fluent:set_locale(locale)
1✔
92
   if options.src then
1✔
NEW
93
      fluent:load_file(options.src, locale)
×
94
   elseif SU.hasContent(content) then
2✔
95
      local input = content[1]
1✔
96
      fluent:add_messages(input, locale)
1✔
97
   end
98
end, nil, nil, true)
182✔
99

100
require("languages.unicode")
181✔
101

102
-- The following languages neither have hyphenation nor specific
103
-- language support at present. This code is here to suppress warnings.
104
SILE.hyphenator.languages.ar = { patterns = {} }
181✔
105
SILE.hyphenator.languages.bo = { patterns = {} }
181✔
106
SILE.hyphenator.languages.sd = { patterns = {} }
181✔
107
SILE.hyphenator.languages.ur = { patterns = {} }
181✔
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

© 2025 Coveralls, Inc