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

sile-typesetter / sile / 6915746301

18 Nov 2023 07:02PM UTC coverage: 56.433% (-12.3%) from 68.751%
6915746301

push

github

web-flow
Merge 8b3fdc301 into f64e235fa

8729 of 15468 relevant lines covered (56.43%)

932.75 hits per line

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

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

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

10
local loadonce = {}
34✔
11

12
SILE.languageSupport = {
34✔
13
  languages = {},
34✔
14
  loadLanguage = function (language)
15
    language = language or SILE.settings:get("document.language")
690✔
16
    language = cldr.locales[language] and language or "und"
690✔
17
    if loadonce[language] then return end
690✔
18
    loadonce[language] = true
38✔
19
    local langresource = string.format("languages.%s", language)
38✔
20
    local gotlang, lang = pcall(require, langresource)
38✔
21
    if not gotlang then
38✔
22
      SU.warn(("Unable to load language feature support (e.g. hyphenation rules) for %s: %s")
×
23
        :format(language, lang:gsub(":.*", "")))
×
24
    end
25
    local ftlresource = string.format("i18n.%s", language)
38✔
26
    SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
38✔
27
    fluent:set_locale(language)
38✔
28
    local gotftl, ftl = pcall(require, ftlresource)
38✔
29
    if not gotftl then
38✔
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
38✔
34
      lang.init()
1✔
35
    end
36
  end
37
}
34✔
38

39
SILE.registerCommand("language", function (options, content)
68✔
40
  local main = SU.required(options, "main", "language setting")
×
41
  SILE.languageSupport.loadLanguage(main)
×
42
  if content[1] then
×
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)
×
49
  end
50
end, nil, nil, true)
34✔
51

52
SILE.registerCommand("fluent", function (options, content)
68✔
53
  local key = content[1]
×
54
  local locale = options.locale or SILE.settings:get("document.language")
×
55
  SU.debug("fluent", "Looking for", key, "in", locale)
×
56
  local entry
57
  if key then
×
58
    fluent:set_locale(locale)
×
59
    entry = fluent:get_message(key)
×
60
  else
61
    SU.warn("Fluent localization function called without passing a valid message id")
×
62
  end
63
  local message
64
  if entry then
×
65
    message = entry:format(options)
×
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")
×
76
end, nil, nil, true)
34✔
77

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

90
require("languages.unicode")
34✔
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 = {} }
34✔
95
SILE.hyphenator.languages.bo = { patterns = {} }
34✔
96
SILE.hyphenator.languages.sd = { patterns = {} }
34✔
97
SILE.hyphenator.languages.ur = { patterns = {} }
34✔
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