1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

home-manager: add basic i18n support

The support for translated strings is, for now, limited to strings
generated in Bash code.
This commit is contained in:
Robert Helgesson 2021-04-30 01:29:39 +02:00
parent 3d46c011d2
commit 9bcad20013
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
13 changed files with 634 additions and 68 deletions

View file

@ -605,10 +605,32 @@ in
''
);
# Text containing Bash commands that will initialize the Home Manager Bash
# library. Most importantly, this will prepare for using translated strings
# in the `hm-modules` text domain.
lib.bash.initHomeManagerLib =
let
domainDir = pkgs.runCommand "hm-modules-messages" {
nativeBuildInputs = [ pkgs.gettext ];
} ''
for path in ${./po}/*.po; do
lang="''${path##*/}"
lang="''${lang%%.*}"
mkdir -p "$out/$lang/LC_MESSAGES"
msgfmt -o "$out/$lang/LC_MESSAGES/hm-modules.mo" "$path"
done
'';
in
''
export TEXTDOMAIN=hm-modules
export TEXTDOMAINDIR=${domainDir}
source ${../lib/bash/home-manager.sh}
'';
home.activationPackage =
let
mkCmd = res: ''
noteEcho Activating ${res.name}
_iNote "Activating %s" "${res.name}"
${res.data}
'';
sortedCommands = hm.dag.topoSort cfg.activation;
@ -622,14 +644,15 @@ in
# Programs that always should be available on the activation
# script's PATH.
activationBinPaths = lib.makeBinPath (
[
pkgs.bash
pkgs.coreutils
pkgs.diffutils # For `cmp` and `diff`.
pkgs.findutils
pkgs.gnugrep
pkgs.gnused
pkgs.ncurses # For `tput`.
with pkgs; [
bash
coreutils
diffutils # For `cmp` and `diff`.
findutils
gettext
gnugrep
gnused
ncurses # For `tput`.
] ++ config.home.extraActivationPath
)
+ optionalString (!cfg.emptyActivationPath) "\${PATH:+:}$PATH";
@ -641,8 +664,7 @@ in
cd $HOME
export PATH="${activationBinPaths}"
. ${./lib-bash/color-echo.sh}
${config.lib.bash.initHomeManagerLib}
${builtins.readFile ./lib-bash/activation-init.sh}