Skip to content

Commit

Permalink
Merge pull request #2064 from alerque/env-locale
Browse files Browse the repository at this point in the history
Export env language var matching document state
  • Loading branch information
alerque authored Nov 14, 2024
2 parents 6d9d6ca + 84fbd7f commit f575d00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/settings.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local setenv = require("rusile").setenv

--- core settings instance
--- @module SILE.settings

Expand Down Expand Up @@ -29,6 +31,8 @@ function settings:_init ()
]]):format(language, language, language, language))
end
fluent:set_locale(language)
os.setlocale(language)
setenv("LANG", language)
end,
help = "Locale for localized language support",
})
Expand Down
7 changes: 7 additions & 0 deletions spec/languages_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
SILE = require("core.sile")

describe("Language module", function ()

it("should set env locale", function ()
SILE.call("language", { main = "tr" })
local syslang = os.getenv("LANG")
assert.is.equal("tr", syslang)
end)

describe("Norwegian", function ()
local hyphenate = SILE.showHyphenationPoints

Expand Down
12 changes: 12 additions & 0 deletions spec/rusile_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ describe("rusile", function ()
end)
end)
end)

describe("setenv", function ()
local setenv = rusile.setenv

it("should effectively set variables before executing system commands", function ()
local before = os.getenv("FOO")
assert.is.equal(type(before), "nil")
setenv("FOO", "bar")
local after = os.getenv("FOO")
assert.is.equal(after, "bar")
end)
end)
end)
2 changes: 1 addition & 1 deletion spec/utilities_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("SILE.utilities", function ()
end)
end)

describe("utf8_to_utf16be_hexencoded ", function ()
describe("utf8_to_utf16be_hexencoded", function ()
it("should hex encode input", function ()
local str = "foo"
local out = "feff0066006f006f"
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#[cfg(not(feature = "static"))]
use mlua::chunk;
use mlua::prelude::*;
#[cfg(not(feature = "static"))]
use std::env;
use std::path::PathBuf;
use std::{env, path::PathBuf};
#[cfg(feature = "cli")]
pub mod cli;

Expand Down Expand Up @@ -60,9 +58,15 @@ pub fn inject_paths(lua: &Lua) {
pub fn get_rusile_exports(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
exports.set("semver", LuaFunction::wrap_raw(types::semver::semver))?;
exports.set("setenv", LuaFunction::wrap_raw(setenv))?;
Ok(exports)
}

fn setenv(key: String, value: String) -> LuaResult<()> {
env::set_var(key, value);
Ok(())
}

pub fn inject_version(lua: &Lua) {
let sile: LuaTable = lua.globals().get("SILE").unwrap();
let mut full_version: String = sile.get("full_version").unwrap();
Expand Down

0 comments on commit f575d00

Please sign in to comment.