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 @@