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

sile-typesetter / sile / 8921272340

02 May 2024 09:00AM UTC coverage: 66.229% (+2.5%) from 63.747%
8921272340

push

github

web-flow
chore(deps): Bump @commitlint/cli from 18.6.1 to 19.3.0 (#2016)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10531 of 15901 relevant lines covered (66.23%)

3880.04 hits per line

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

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

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

10
local loadonce = {}
85✔
11

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

39
SILE.registerCommand("language", function (options, content)
170✔
40
  local main = SU.required(options, "main", "language setting")
13✔
41
  SILE.languageSupport.loadLanguage(main)
13✔
42
  if content[1] then
13✔
43
    SILE.settings:temporarily(function ()
×
44
      SILE.settings:set("document.language", main)
×
45
      SILE.process(content)
×
46
    end)
47
  else
48
    SILE.settings:set("document.language", main)
13✔
49
  end
50
end, nil, nil, true)
98✔
51

52
SILE.registerCommand("fluent", function (options, content)
170✔
53
  local key = content[1]
7✔
54
  local locale = options.locale or SILE.settings:get("document.language")
7✔
55
  SU.debug("fluent", "Looking for", key, "in", locale)
7✔
56
  local entry
57
  if key then
7✔
58
    fluent:set_locale(locale)
7✔
59
    entry = fluent:get_message(key)
14✔
60
  else
61
    SU.warn("Fluent localization function called without passing a valid message id")
×
62
  end
63
  local message
64
  if entry then
7✔
65
    message = entry:format(options)
14✔
66
  else
67
    SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
68
    fluent:set_locale('und')
×
69
    entry = fluent:get_message(key)
×
70
    if entry then
×
71
      message = entry:format(options)
×
72
    end
73
    fluent:set_locale(locale)
×
74
  end
75
  SILE.processString(("<sile>%s</sile>"):format(message), "xml")
7✔
76
end, nil, nil, true)
92✔
77

78
SILE.registerCommand("ftl", function (options, content)
170✔
79
  local locale = options.locale or SILE.settings:get("document.language")
1✔
80
  SU.debug("fluent", "Loading message(s) into locale", locale)
1✔
81
  fluent:set_locale(locale)
1✔
82
  if options.src then
1✔
83
    fluent:load_file(options.src, locale)
×
84
  elseif SU.hasContent(content) then
2✔
85
    local input = content[1]
1✔
86
    fluent:add_messages(input, locale)
1✔
87
  end
88
end, nil, nil, true)
86✔
89

90
require("languages.unicode")
85✔
91

92
-- The following languages neither have hyphenation nor specific
93
-- language support at present. This code is here to suppress warnings.
94
SILE.hyphenator.languages.ar = { patterns = {} }
85✔
95
SILE.hyphenator.languages.bo = { patterns = {} }
85✔
96
SILE.hyphenator.languages.sd = { patterns = {} }
85✔
97
SILE.hyphenator.languages.ur = { patterns = {} }
85✔
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