aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-08-19 09:29:08 +0200
committerTeddy Wing2017-08-19 09:29:08 +0200
commitabbe2141c56aaab9cf8b4913803c66096728ac16 (patch)
tree95689266bad0580296d8ef1dec229f06fe0010e7
parent6cd279630923cdcd053e373b56b8bc0ad85a9b08 (diff)
downloadsorbot-abbe2141c56aaab9cf8b4913803c66096728ac16.tar.bz2
Try to get I18n working
An unsuccessful attempt at getting i18n working through Shakespeare. Had a little help from: https://gist.github.com/nicolashery/f87467fb37da2b00cec1eed028f51e60 Unfortunately, I can't figure out how to get this working. Even before, without the locale stuff and defining a custom `translate` function, when I tried using Shakespeare's `_{}` function, I was, and still am, getting this error: src/Plugin/GitHubCommit.hs:38:29: error: Data constructor not in scope: MsgGitHubCommitRepoURLNotFound Yes, obviously, that makes sense. But how do I get it to be in scope if it isn't even in my code? What? I'm giving up on Shakespeare for i18n. It was a nice idea, I liked the fact that strings were stored in external files, but I don't know how to do this, I can't find the right resources online to use this in a non-web non-template context, and it's becoming a pain. Going to get rid of all this code and just use regular Haskell data types to do it as described in https://wiki.haskell.org/Internationalization_of_Haskell_programs
-rw-r--r--src/I18n.hs21
-rw-r--r--src/Plugin/GitHubCommit.hs5
2 files changed, 22 insertions, 4 deletions
diff --git a/src/I18n.hs b/src/I18n.hs
index 9b9f870..988c823 100644
--- a/src/I18n.hs
+++ b/src/I18n.hs
@@ -1,13 +1,30 @@
+{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
-module I18n where
+module I18n
+ ( Locale(..)
+ , RenderMessage
+
+ , mkMessage
+ , translate
+ ) where
import qualified Data.Text as T
-import Text.Shakespeare.I18N (mkMessage, renderMessage)
+import Text.Shakespeare.I18N (mkMessage, renderMessage, RenderMessage)
data Bot = Bot
+data Locale = EN | FR
+
+toISOLocale :: Locale -> T.Text
+toISOLocale EN = "en"
+toISOLocale FR = "fr"
+
mkMessage "Bot" "messages" "en"
+
+translate :: (RenderMessage Bot b) => Locale -> b -> T.Text
+translate locale message =
+ renderMessage Bot [(toISOLocale locale)] message
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index a857604..23de2fa 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -33,8 +33,9 @@ gitHubCommitAction message = do
return $ respond rs
where
respond [] =
- Left "I couldn't find a repo URL for this channel. \
- \Try `git remote set origin REPO_URL`."
+ -- Left "I couldn't find a repo URL for this channel. \
+ -- \Try `git remote set origin REPO_URL`."
+ Left $ translate EN MsgGitHubCommitRepoURLNotFound
respond ((RepoUrlRow r):_) =
Right $ r `T.append` "/commits/" `T.append` T.pack (
M.textStr message =~ matchRegex gitHubCommit)