aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-05-14 07:50:08 -0300
committerEuAndreh <eu@euandre.org>2025-05-14 07:51:03 -0300
commit008c2bd3ee280fa797533dd3a352805806f29012 (patch)
tree46e912bc48a8370044947bfecaa294ed024e6ace
parentsrc/gotext.go: Remove global `opts` shared variable (diff)
downloadgotext-008c2bd3ee280fa797533dd3a352805806f29012.tar.gz
gotext-008c2bd3ee280fa797533dd3a352805806f29012.tar.xz
src/gotext.go: Fix usage of `var`
-rw-r--r--src/gotext.go104
1 files changed, 56 insertions, 48 deletions
diff --git a/src/gotext.go b/src/gotext.go
index 2df437e..1bc4929 100644
--- a/src/gotext.go
+++ b/src/gotext.go
@@ -30,6 +30,44 @@ import "C"
+var (
+ formatTime = func() string {
+ if false {
+ // FIXME
+ return time.Now().Format("2006-01-02 15:04-0700")
+ }
+ return "2015-06-30T14:48:00-03:00"
+ }
+
+ // FIXME: are these comments useful
+
+ // LC_ALL is for all of the locale.
+ LC_ALL = uint(C.LC_ALL)
+
+ // LC_COLLATE is for regular expression matching (it determines the meaning of
+ // range expressions and equivalence classes) and string collation.
+ LC_COLLATE = uint(C.LC_COLLATE)
+
+ // LC_CTYPE is for regular expression matching, character classification,
+ // conversion, case-sensitive comparison, and wide character functions.
+ LC_CTYPE = uint(C.LC_CTYPE)
+
+ // LC_MESSAGES is for localizable natural-language messages.
+ LC_MESSAGES = uint(C.LC_MESSAGES)
+
+ // LC_MONETARY is for monetary formatting.
+ LC_MONETARY = uint(C.LC_MONETARY)
+
+ // LC_NUMERIC is for number formatting (such as the decimal point and the
+ // thousands separator).
+ LC_NUMERIC = uint(C.LC_NUMERIC)
+
+ // LC_TIME is for time and date formatting.
+ LC_TIME = uint(C.LC_TIME)
+)
+
+
+
type msgID struct {
msgidPlural string
comment string
@@ -117,7 +155,8 @@ func inspectNodeForTranslations(
n ast.Node,
) bool {
// FIXME: this assume we always have a "gettext.Gettext" style keyword
- var gettextSelector, gettextFuncName string
+ gettextSelector := ""
+ gettextFuncName := ""
l := strings.Split(args.keyword, ".")
if len(l) > 1 {
@@ -127,7 +166,8 @@ func inspectNodeForTranslations(
gettextFuncName = l[0]
}
- var gettextSelectorPlural, gettextFuncNamePlural string
+ gettextSelectorPlural := ""
+ gettextFuncNamePlural := ""
l = strings.Split(args.keywordPlural, ".")
if len(l) > 1 {
@@ -139,7 +179,8 @@ func inspectNodeForTranslations(
switch x := n.(type) {
case *ast.CallExpr:
- var i18nStr, i18nStrPlural string
+ i18nStr := ""
+ i18nStrPlural := ""
//if sel, ok := x.Fun.(*ast.Ident); ok {
//}
@@ -243,12 +284,18 @@ func processSingleGoSource(
return nil
}
-var formatTime = func() string {
- if false {
- // FIXME
- return time.Now().Format("2006-01-02 15:04-0700")
+func formatOutput(in string) string {
+ // split string with \n into multiple lines
+ // to make the output nicer
+ out := strings.Replace(in, "\\n", "\\n\"\n\"", -1)
+ // cleanup too aggressive splitting (empty "" lines)
+ out = strings.TrimSuffix(out, "\"\n\"")
+
+ if strings.Count(out, "\n") == 0 {
+ return out
+ } else {
+ return "\"\n\"" + out
}
- return "2015-06-30T14:48:00-03:00"
}
func writePotFile(out io.Writer) {
@@ -290,19 +337,7 @@ func writePotFile(out io.Writer) {
if msgid.formatHint != "" {
fmt.Fprintf(out, "#, %s\n", msgid.formatHint)
}
- var formatOutput = func(in string) string {
- // split string with \n into multiple lines
- // to make the output nicer
- out := strings.Replace(in, "\\n", "\\n\"\n\"", -1)
- // cleanup too aggressive splitting (empty "" lines)
- out = strings.TrimSuffix(out, "\"\n\"")
-
- if strings.Count(out, "\n") == 0 {
- return out
- } else {
- return "\"\n\"" + out
- }
- }
+
fmt.Fprintf(out, "msgid \"%v\"\n", formatOutput(k))
if msgid.msgidPlural != "" {
fmt.Fprintf(out, "msgid_plural \"%v\"\n", formatOutput(msgid.msgidPlural))
@@ -399,33 +434,6 @@ func Main() {
writePotFile(os.Stdout)
}
-// FIXME: are these comments useful
-var (
- // LcAll is for all of the locale.
- LC_ALL = uint(C.LC_ALL)
-
- // LC_Collate is for regular expression matching (it determines the meaning of
- // range expressions and equivalence classes) and string collation.
- LC_COLLATE = uint(C.LC_COLLATE)
-
- // LC_Ctype is for regular expression matching, character classification,
- // conversion, case-sensitive comparison, and wide character functions.
- LC_CTYPE = uint(C.LC_CTYPE)
-
- // LC_Messages is for localizable natural-language messages.
- LC_MESSAGES = uint(C.LC_MESSAGES)
-
- // LC_Monetary is for monetary formatting.
- LC_MONETARY = uint(C.LC_MONETARY)
-
- // LC_Numeric is for number formatting (such as the decimal point and the
- // thousands separator).
- LC_NUMERIC = uint(C.LC_NUMERIC)
-
- // LC_Time is for time and date formatting.
- LC_TIME = uint(C.LC_TIME)
-)
-
// SetLocale sets the program's current locale.
func SetLocale(category uint, locale string) string {
clocale := C.CString(locale)