i18n of forms.

Portnov [2009-07-17 04:54:52]
i18n of forms.
Filename
Blog/Blog.hs
Blog/Extensions/FormProcessors.hs
Blog/Models.hs
Blog/po/ru.po
Framework/Forms/Rendering.hs
Framework/GetText/HTML.hs
diff --git a/Blog/Blog.hs b/Blog/Blog.hs
index 4921f20..870727a 100644
--- a/Blog/Blog.hs
+++ b/Blog/Blog.hs
@@ -11,7 +11,7 @@ import Framework.Modules.Auth.Utils
 import Framework.Modules.TextCaptcha.FormProcessors
 import Framework.Modules.Registration.Forms

-import Models
+import Models hiding (__)

 urlconf ::  URLConf
 urlconf = "blog" // "new" --> newpost
diff --git a/Blog/Extensions/FormProcessors.hs b/Blog/Extensions/FormProcessors.hs
index 1692506..975a7f0 100644
--- a/Blog/Extensions/FormProcessors.hs
+++ b/Blog/Extensions/FormProcessors.hs
@@ -2,6 +2,7 @@ module Extensions.FormProcessors where

 import Framework.Controller
 import Framework.Forms.Types
+import Framework.GetText.HTML

 import Framework.Modules.TextCaptcha.FormProcessors

@@ -9,5 +10,5 @@ import Framework.Modules.TextCaptcha.FormProcessors
 formProcessors :: FormProcessors
 formProcessors = [addCaptcha ["commentform"]]

-htmlProcessors = []
+htmlProcessors = [translateHTML]

diff --git a/Blog/Models.hs b/Blog/Models.hs
index 363f86a..ab8cbd6 100644
--- a/Blog/Models.hs
+++ b/Blog/Models.hs
@@ -13,13 +13,15 @@ import Framework.Forms.ModelForm
 import Framework.ORM
 import Framework.Modules.Formatters.Markdown

+__ = id
+
 postModel = emptyModel {
     mName = "post",
     mTable = "posts",
     mFields = ["id" ::: PrimaryKey,
                "dt" ::: CurrentDateColumn,
-               ("title" ::: StringColumn) `ValidateBy` notEmpty,
-               ("body"  ::: StringColumn) `ValidateBy` notEmpty `UsingWidget` textarea],
+               (__ "title") ::: StringColumn `ValidateBy` notEmpty,
+               (__ "body")  ::: StringColumn `ValidateBy` notEmpty `UsingWidget` textarea],
     mCached = ["ncomments" ::: IntegerColumn],
     defaultOrdering = [Desceding "dt"],
     perPage = Just 5
@@ -55,8 +57,8 @@ commentModel = emptyModel {
     mFields = ["id" ::: PrimaryKey,
                "pid" ::: ForeignKey postModel "id",
                "dt" ::: CurrentDateColumn,
-               "author" ::: StringColumn,
-               ("body" ::: StringColumn) `ValidateBy` notEmpty `UsingWidget` textarea ],
+               (__ "author") ::: StringColumn,
+               (__ "body") ::: StringColumn `ValidateBy` notEmpty `UsingWidget` textarea ],
     mCached = [],
     defaultOrdering = [Asceding "dt"]
     }
diff --git a/Blog/po/ru.po b/Blog/po/ru.po
index 4d41775..66735a1 100644
--- a/Blog/po/ru.po
+++ b/Blog/po/ru.po
@@ -13,6 +13,22 @@ msgstr ""
 "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%"
 "10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"

-#: Blog.hs:0
+#: Blog/Blog.hs:0
 msgid "Hello world!"
 msgstr "Привет, Мир!"
+
+#: Blog/Models.hs:0
+msgid "Title:"
+msgstr "Заголовок:"
+
+#: Blog/Models.hs:0
+msgid "Body:"
+msgstr "Текст:"
+
+#: Blog/Models.hs:0
+msgid "Author:"
+msgstr "Автор:"
+
+#: Framework/Modules/Auth/Controllers.hs:0
+msgid "Authentithication failed."
+msgstr ""
diff --git a/Framework/Forms/Rendering.hs b/Framework/Forms/Rendering.hs
index e25300e..bddf00b 100644
--- a/Framework/Forms/Rendering.hs
+++ b/Framework/Forms/Rendering.hs
@@ -23,7 +23,7 @@ processForm ::  Form -> FormController
 processForm = processForm' formProcessors

 processHtmlForm :: HTMLForm -> AController String
-processHtmlForm form = (return.tagToHtml) =<< (ioPipe' htmlProcessors $ formToHTML form)
+processHtmlForm form = (return.toHtml) =<< (ioPipe' htmlProcessors [formToHTML form])

 -- | Generate a form, maybe filled with already-entered data. This never does returnNow.
 renderCreateForm :: Form                  -- ^ A form
diff --git a/Framework/GetText/HTML.hs b/Framework/GetText/HTML.hs
new file mode 100644
index 0000000..7423a24
--- /dev/null
+++ b/Framework/GetText/HTML.hs
@@ -0,0 +1,19 @@
+module Framework.GetText.HTML where
+
+import Framework.Controller
+import Framework.Forms.HTMLTypes
+import Framework.Forms.Types
+import qualified Framework.GetText.Controller as C
+
+__ = id
+
+translateHTML :: HTML -> HTMLController
+translateHTML lst = mapM translateTag lst
+
+translateTag :: HTMLTag-> AController HTMLTag
+translateTag (Tag n a lst m) = do
+    lst' <- translateHTML lst
+    return $ Tag n a lst' m
+translateTag (Text t) = do
+    t' <- if null t then return "" else C.__ t
+    return $ Text t'
ViewGit