From 89ca5ee823149ef557572d6682e1832ed960455c Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 17 Jun 2019 09:36:31 +1000 Subject: [PATCH] langf now works in transpiled templates, albeit a little inefficiently. Removed the quick_topic.add_poll_option phrase. Added the quick_topic.add_poll_option_first phrase. Changed the topic.reply_add_poll_option phrase. Added the topic.reply_add_poll_option_first phrase. --- common/pages.go | 1 + common/templates/context.go | 5 +++ common/templates/templates.go | 54 ++++++++++++++++++++++++++-- langs/english.json | 5 +-- public/member.js | 1 + templates/topic.html | 4 +-- templates/topic_alt_quick_reply.html | 6 ++-- templates/topic_c_poll_input.html | 4 +-- templates/topics_quick_topic.html | 50 +++++++++++++------------- 9 files changed, 94 insertions(+), 36 deletions(-) diff --git a/common/pages.go b/common/pages.go index 6304116b..fe3f57aa 100644 --- a/common/pages.go +++ b/common/pages.go @@ -179,6 +179,7 @@ type TopicCAttachItem struct { } type TopicCPollInput struct { Index int + Place string } type TopicPage struct { diff --git a/common/templates/context.go b/common/templates/context.go index f91be400..6842fa55 100644 --- a/common/templates/context.go +++ b/common/templates/context.go @@ -49,6 +49,11 @@ func (con *CContext) PushPhrase(langIndex int) (index int) { return con.LastBufIndex() } +func (con *CContext) PushPhrasef(langIndex int, args string) (index int) { + *con.OutBuf = append(*con.OutBuf, OutBufferFrame{args, "langf", con.TemplateName, langIndex, nil}) + return con.LastBufIndex() +} + func (con *CContext) StartLoop(body string) (index int) { con.LoopDepth++ return con.Push("startloop", body) diff --git a/common/templates/templates.go b/common/templates/templates.go index 5692ea81..236820a9 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -11,6 +11,7 @@ import ( "runtime/debug" "strconv" "strings" + "unicode" "text/template/parse" "time" ) @@ -106,7 +107,7 @@ func NewCTemplateSet(in string) *CTemplateSet { "hasWidgets": true, "elapsed": true, "lang": true, - //"langf":true, + "langf":true, "level": true, "bunit": true, "abstime": true, @@ -1109,7 +1110,56 @@ ArgLoop: notident = true con.PushPhrase(len(c.langIndexToName) - 1) break ArgLoop - // TODO: Implement langf + case "langf": + // TODO: Implement string literals properly + leftOperand := node.Args[pos+1].String() + if len(leftOperand) == 0 { + panic("The left operand for the language string cannot be left blank") + } + if leftOperand[0] != '"' { + panic("Phrase names cannot be dynamic") + } + + var olist []string + for i := pos+2; i < len(node.Args); i++ { + op := node.Args[i].String() + if op != "" { + if op[0] == '.' || op[0] == '$' { + panic("langf args cannot be dynamic") + } + if op[0] != '"' && !unicode.IsDigit(rune(op[0])) { + break + } + olist = append(olist,op) + } + } + if len(olist) == 0 { + panic("You must provide parameters for langf") + } + + var ob = "," + for _, op := range olist { + allNum := true + for _, o := range op { + if !unicode.IsDigit(o) { + allNum = false + } + } + if allNum { + ob += strings.Replace(op,"\"","\\\"",-1) + "," + } else { + ob += ob + "," + } + } + if ob != "" { + ob = ob[:len(ob)-1] + } + + // TODO: Implement string literals properly + // ! Slightly crude but it does the job + litString("phrases.GetTmplPhrasef("+leftOperand+ob+")", false) + c.importMap[langPkg] = langPkg + break ArgLoop case "level": // TODO: Implement level literals leftOperand := node.Args[pos+1].String() diff --git a/langs/english.json b/langs/english.json index 0bff7b7d..84864c14 100644 --- a/langs/english.json +++ b/langs/english.json @@ -546,7 +546,7 @@ "quick_topic.avatar_alt":"Your Avatar", "quick_topic.whatsup":"What's up?", "quick_topic.content_placeholder":"Insert post here", - "quick_topic.add_poll_option":"Poll option", + "quick_topic.add_poll_option_first":"Poll option #0", "quick_topic.create_topic_button":"Create Topic", "quick_topic.create_topic_button_short":"New Topic", "quick_topic.add_poll_button":"Add Poll", @@ -653,7 +653,8 @@ "topic.reply_aria":"The quick reply form", "topic.reply_content":"Insert reply here", "topic.reply_content_alt":"What do you think?", - "topic.reply_add_poll_option":"Poll option", + "topic.reply_add_poll_option":"Poll option #%d", + "topic.reply_add_poll_option_first":"Poll option #0", "topic.reply_button":"Create Reply", "topic.reply_add_poll_button":"Add Poll", "topic.reply_add_file_button":"Add File", diff --git a/public/member.js b/public/member.js index a26501b6..ee004d4c 100644 --- a/public/member.js +++ b/public/member.js @@ -286,6 +286,7 @@ if(dataPollInput != (pollInputIndex-1)) return; $(".poll_content_row .formitem").append(Template_topic_c_poll_input({ Index: pollInputIndex, + Place: phraseBox["topic"]["topic.reply_add_poll_option"].replace("%d",pollInputIndex), })); pollInputIndex++; console.log("new pollInputIndex: ", pollInputIndex); diff --git a/templates/topic.html b/templates/topic.html index 104242c0..cda755cb 100644 --- a/templates/topic.html +++ b/templates/topic.html @@ -82,10 +82,10 @@
-
+
- +
diff --git a/templates/topic_alt_quick_reply.html b/templates/topic_alt_quick_reply.html index 249cef5c..ce8372e4 100644 --- a/templates/topic_alt_quick_reply.html +++ b/templates/topic_alt_quick_reply.html @@ -1,6 +1,6 @@
-
 
+
 
{{if .CurrentUser.Tag}}
{{else}}
{{end}} @@ -17,10 +17,10 @@
-
+
- +
diff --git a/templates/topic_c_poll_input.html b/templates/topic_c_poll_input.html index 830d700b..4d1f781f 100644 --- a/templates/topic_c_poll_input.html +++ b/templates/topic_c_poll_input.html @@ -1,5 +1,5 @@ -
+
- +
\ No newline at end of file diff --git a/templates/topics_quick_topic.html b/templates/topics_quick_topic.html index 2d2c1195..c6e86b47 100644 --- a/templates/topics_quick_topic.html +++ b/templates/topics_quick_topic.html @@ -1,26 +1,26 @@ - -
-
- -
+ +
+
+ +
+
+
+
+
+ + +
-
-
-
- - - -
-
-
-
-
- - - {{if .CurrentUser.Perms.UploadFiles}} - - -
{{end}} - -
-
\ No newline at end of file +
+
+
+
+ + + {{if .CurrentUser.Perms.UploadFiles}} + + +
{{end}} + +
+
\ No newline at end of file