# This shell library is Git's interface to gettext.sh. See po/README # for usage instructions. # # Copyright (c) 2010 Ævar Arnfjörð Bjarmason # # Export the TEXTDOMAIN* data that we need for Git global TEXTDOMAIN := 'git' export TEXTDOMAIN if test -z $GIT_TEXTDOMAINDIR { global TEXTDOMAINDIR := '"@@LOCALEDIR@@'" } else { global TEXTDOMAINDIR := $GIT_TEXTDOMAINDIR } export TEXTDOMAINDIR # First decide what scheme to use... global GIT_INTERNAL_GETTEXT_SH_SCHEME := 'fallthrough' if test -n "@@USE_GETTEXT_SCHEME@@" { global GIT_INTERNAL_GETTEXT_SH_SCHEME := '"@@USE_GETTEXT_SCHEME@@'" } elif test -n $GIT_INTERNAL_GETTEXT_TEST_FALLBACKS { : no probing necessary } elif test -n $GIT_GETTEXT_POISON { global GIT_INTERNAL_GETTEXT_SH_SCHEME := 'poison' } elif type gettext.sh >/dev/null !2 > !1 { # GNU libintl's gettext.sh global GIT_INTERNAL_GETTEXT_SH_SCHEME := 'gnu' } elif test $[gettext -h !2 > !1] = "-h" { # gettext binary exists but no gettext.sh. likely to be a gettext # binary on a Solaris or something that is not GNU libintl and # lack eval_gettext. global GIT_INTERNAL_GETTEXT_SH_SCHEME := 'gettext_without_eval_gettext' } export GIT_INTERNAL_GETTEXT_SH_SCHEME # ... and then follow that decision. matchstr $GIT_INTERNAL_GETTEXT_SH_SCHEME { gnu { # Use libintl's gettext.sh, or fall back to English if we can't. source gettext.sh } gettext_without_eval_gettext { # Solaris has a gettext(1) but no eval_gettext(1) proc eval_gettext { gettext $1 | shell { export PATH $[git sh-i18n--envsubst --variables $1]; git sh-i18n--envsubst $1 } } proc eval_ngettext { ngettext $1 $2 $3 | shell { export PATH $[git sh-i18n--envsubst --variables $2]; git sh-i18n--envsubst $2 } } } poison { # Emit garbage so that tests that incorrectly rely on translatable # strings will fail. proc gettext { printf "%s" "# GETTEXT POISON #" } proc eval_gettext { printf "%s" "# GETTEXT POISON #" } proc eval_ngettext { printf "%s" "# GETTEXT POISON #" } } * { proc gettext { printf "%s" $1 } proc eval_gettext { printf "%s" $1 | shell { export PATH $[git sh-i18n--envsubst --variables $1]; git sh-i18n--envsubst $1 } } proc eval_ngettext { shell {test $3 = 1 && printf "%s" $1 || printf "%s" $2} | shell { export PATH $[git sh-i18n--envsubst --variables $2]; git sh-i18n--envsubst $2 } } } } # Git-specific wrapper functions proc gettextln { gettext $1 echo } proc eval_gettextln { eval_gettext $1 echo } (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:TEXTDOMAIN) op:Equal rhs:{(git)} spids:[19])] spids: [19] ) (C {(export)} {(TEXTDOMAIN)}) (If arms: [ (if_arm cond: [(C {(test)} {(-z)} {(DQ ($ VSub_Name "$GIT_TEXTDOMAINDIR"))})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEXTDOMAINDIR) op: Equal rhs: {(DQ ("@@LOCALEDIR@@"))} spids: [39] ) ] spids: [39] ) ] spids: [-1 36] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TEXTDOMAINDIR) op: Equal rhs: {(DQ ($ VSub_Name "$GIT_TEXTDOMAINDIR"))} spids: [47] ) ] spids: [47] ) ] spids: [44 52] ) (C {(export)} {(TEXTDOMAINDIR)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_INTERNAL_GETTEXT_SH_SCHEME) op: Equal rhs: {(fallthrough)} spids: [62] ) ] spids: [62] ) (If arms: [ (if_arm cond: [(C {(test)} {(-n)} {(DQ ("@@USE_GETTEXT_SCHEME@@"))})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_INTERNAL_GETTEXT_SH_SCHEME) op: Equal rhs: {(DQ ("@@USE_GETTEXT_SCHEME@@"))} spids: [78] ) ] spids: [78] ) ] spids: [-1 75] ) (if_arm cond: [(C {(test)} {(-n)} {(DQ ($ VSub_Name "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"))})] action: [(C {(Lit_Other ":")} {(no)} {(probing)} {(necessary)})] spids: [83 93] ) (if_arm cond: [(C {(test)} {(-n)} {(DQ ($ VSub_Name "$GIT_GETTEXT_POISON"))})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_INTERNAL_GETTEXT_SH_SCHEME) op: Equal rhs: {(poison)} spids: [117] ) ] spids: [117] ) ] spids: [104 114] ) (if_arm cond: [ (SimpleCommand words: [{(type)} {(gettext.sh)}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[126]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[129]) ] ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_INTERNAL_GETTEXT_SH_SCHEME) op: Equal rhs: {(gnu)} spids: [139] ) ] spids: [139] ) ] spids: [120 132] ) (if_arm cond: [ (C {(test)} { (DQ (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(gettext)} {(-h)}] redirects: [(Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[152])] ) ] ) left_token: spids: [147 154] ) ) } {(Lit_Other "=")} {(DQ (-h))} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_INTERNAL_GETTEXT_SH_SCHEME) op: Equal rhs: {(gettext_without_eval_gettext)} spids: [178] ) ] spids: [178] ) ] spids: [142 163] ) ] spids: [-1 181] ) (C {(export)} {(GIT_INTERNAL_GETTEXT_SH_SCHEME)}) (Case to_match: {(DQ ($ VSub_Name "$GIT_INTERNAL_GETTEXT_SH_SCHEME"))} arms: [ (case_arm pat_list:[{(gnu)}] action:[(C {(.)} {(gettext.sh)})] spids:[199200212-1]) (case_arm pat_list: [{(gettext_without_eval_gettext)}] action: [ (FuncDef name: eval_gettext body: (BraceGroup children: [ (Pipeline children: [ (C {(gettext)} {(DQ ($ VSub_Number "$1"))}) (Subshell child: (CommandList children: [ (Sentence child: (C {(export)} {(PATH)} { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(sh-i18n--envsubst)} {(--variables)} {(DQ ($ VSub_Number "$1"))} ) ] ) left_token: spids: [245 255] ) } ) terminator: ) (C {(git)} {(sh-i18n--envsubst)} {(DQ ($ VSub_Number "$1"))}) ] ) spids: [238 268] ) ] negated: False ) ] spids: [227] ) spids: [222 226] ) (FuncDef name: eval_ngettext body: (BraceGroup children: [ (Pipeline children: [ (C {(ngettext)} {(DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Number "$2"))} {(DQ ($ VSub_Number "$3"))} ) (Subshell child: (CommandList children: [ (Sentence child: (C {(export)} {(PATH)} { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(sh-i18n--envsubst)} {(--variables)} {(DQ ($ VSub_Number "$2"))} ) ] ) left_token: spids: [306 316] ) } ) terminator: ) (C {(git)} {(sh-i18n--envsubst)} {(DQ ($ VSub_Number "$2"))}) ] ) spids: [299 329] ) ] negated: False ) ] spids: [280] ) spids: [275 279] ) ] spids: [214 215 335 -1] ) (case_arm pat_list: [{(poison)}] action: [ (FuncDef name: gettext body: (BraceGroup children: [(C {(printf)} {(DQ ("%s"))} {(DQ ("# GETTEXT POISON #"))})] spids: [354] ) spids: [349 353] ) (FuncDef name: eval_gettext body: (BraceGroup children: [(C {(printf)} {(DQ ("%s"))} {(DQ ("# GETTEXT POISON #"))})] spids: [377] ) spids: [372 376] ) (FuncDef name: eval_ngettext body: (BraceGroup children: [(C {(printf)} {(DQ ("%s"))} {(DQ ("# GETTEXT POISON #"))})] spids: [400] ) spids: [395 399] ) ] spids: [337 338 417 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (FuncDef name: gettext body: (BraceGroup children: [(C {(printf)} {(DQ ("%s"))} {(DQ ($ VSub_Number "$1"))})] spids: [428] ) spids: [423 427] ) (FuncDef name: eval_gettext body: (BraceGroup children: [ (Pipeline children: [ (C {(printf)} {(DQ ("%s"))} {(DQ ($ VSub_Number "$1"))}) (Subshell child: (CommandList children: [ (Sentence child: (C {(export)} {(PATH)} { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(sh-i18n--envsubst)} {(--variables)} {(DQ ($ VSub_Number "$1"))} ) ] ) left_token: spids: [473 483] ) } ) terminator: ) (C {(git)} {(sh-i18n--envsubst)} {(DQ ($ VSub_Number "$1"))}) ] ) spids: [466 496] ) ] negated: False ) ] spids: [451] ) spids: [446 450] ) (FuncDef name: eval_ngettext body: (BraceGroup children: [ (Pipeline children: [ (Subshell child: (AndOr children: [ (C {(test)} {(DQ ($ VSub_Number "$3"))} {(Lit_Other "=")} {(1)}) (AndOr children: [ (C {(printf)} {(DQ ("%s"))} {(DQ ($ VSub_Number "$1"))}) (C {(printf)} {(DQ ("%s"))} {(DQ ($ VSub_Number "$2"))}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) spids: [511 545] ) (Subshell child: (CommandList children: [ (Sentence child: (C {(export)} {(PATH)} { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(sh-i18n--envsubst)} {(--variables)} {(DQ ($ VSub_Number "$2"))} ) ] ) left_token: spids: [556 566] ) } ) terminator: ) (C {(git)} {(sh-i18n--envsubst)} {(DQ ($ VSub_Number "$2"))}) ] ) spids: [549 579] ) ] negated: False ) ] spids: [508] ) spids: [503 507] ) ] spids: [419 420 585 -1] ) ] spids: [191 197 587] ) (FuncDef name: gettextln body: (BraceGroup children: [(C {(gettext)} {(DQ ($ VSub_Number "$1"))}) (C {(echo)})] spids: [598] ) spids: [593 597] ) (FuncDef name: eval_gettextln body: (BraceGroup children: [(C {(eval_gettext)} {(DQ ($ VSub_Number "$1"))}) (C {(echo)})] spids: [618] ) spids: [613 617] ) ] )