From d617a77209aef08d485df4ab6adb604e63424ea8 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Thu, 3 Sep 2020 13:39:42 +0300 Subject: [PATCH] add example for: #1614 --- _examples/i18n/locales/el-GR/locale_el-GR.ini | 3 ++- _examples/i18n/locales/en-US/locale_en-US.ini | 3 ++- _examples/i18n/locales/zh-CN/locale_zh-CN.ini | 3 ++- _examples/i18n/main.go | 4 ++++ _examples/i18n/views/index.html | 6 +++++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/_examples/i18n/locales/el-GR/locale_el-GR.ini b/_examples/i18n/locales/el-GR/locale_el-GR.ini index a99e7fcc..31ac5689 100644 --- a/_examples/i18n/locales/el-GR/locale_el-GR.ini +++ b/_examples/i18n/locales/el-GR/locale_el-GR.ini @@ -1 +1,2 @@ -hi = γεια, %s \ No newline at end of file +hi = γεια, %s +userProfilePublicDescription = περιγραφή προφιλ \ No newline at end of file diff --git a/_examples/i18n/locales/en-US/locale_en-US.ini b/_examples/i18n/locales/en-US/locale_en-US.ini index b2a39433..2c24e82a 100644 --- a/_examples/i18n/locales/en-US/locale_en-US.ini +++ b/_examples/i18n/locales/en-US/locale_en-US.ini @@ -1 +1,2 @@ -hi = hello, %s \ No newline at end of file +hi = hello, %s +userProfilePublicDescription = profile description \ No newline at end of file diff --git a/_examples/i18n/locales/zh-CN/locale_zh-CN.ini b/_examples/i18n/locales/zh-CN/locale_zh-CN.ini index 0a7c91b0..8ccd66fa 100644 --- a/_examples/i18n/locales/zh-CN/locale_zh-CN.ini +++ b/_examples/i18n/locales/zh-CN/locale_zh-CN.ini @@ -1 +1,2 @@ -hi = 您好,%s \ No newline at end of file +hi = 您好,%s +userProfilePublicDescription = 个人资料描述 \ No newline at end of file diff --git a/_examples/i18n/main.go b/_examples/i18n/main.go index 2b11ac03..3b5a167e 100644 --- a/_examples/i18n/main.go +++ b/_examples/i18n/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "html/template" "github.com/kataras/iris/v12" ) @@ -78,6 +79,9 @@ func newApp() *iris.Application { app.Get("/templates", func(ctx iris.Context) { ctx.View("index.html", iris.Map{ "tr": ctx.Tr, // word, arguments... {call .tr "hi" "iris"}} + "trUnsafe": func(message string, args ...interface{}) template.HTML { + return template.HTML(ctx.Tr(message, args...)) + }, }) // Note that, diff --git a/_examples/i18n/views/index.html b/_examples/i18n/views/index.html index 32bc8a6b..64b40e7f 100644 --- a/_examples/i18n/views/index.html +++ b/_examples/i18n/views/index.html @@ -6,4 +6,8 @@

Test translate of any language template function [static] ("language", "word", arguments...)
tr "zh-CN" "hi" "iris"

-{{tr "zh-CN" "hi" "iris"}} \ No newline at end of file +{{tr "zh-CN" "hi" "iris"}} + +

Test HTML link ("word", arguments...)
call .trUnsafe "trUnsafe" "userProfilePublicDescription" "https://iris-go.com"

+ +{{call .trUnsafe "userProfilePublicDescription" "https://iris-go.com"}} \ No newline at end of file