aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2017-08-19 10:43:17 +0200
committerTeddy Wing2017-08-19 11:42:35 +0200
commit9c777bd1f6e9d5ba456f3f5db0986b3eb71d9fce (patch)
tree40d563500bdcc73c820484a9d24bfc7d056f4d7b /src
parentabbe2141c56aaab9cf8b4913803c66096728ac16 (diff)
downloadsorbot-9c777bd1f6e9d5ba456f3f5db0986b3eb71d9fce.tar.bz2
I18n.hs: Implement custom i18n using Haskell data types
Follow the example https://wiki.haskell.org/Internationalization_of_Haskell_programs_using_Haskell_data_types to get i18n. Get rid of the Shakespeare-I18N code. The idea of using text files to define translation strings was nice, but since I couldn't get it working with ease and couldn't find examples outside of a Yesod context, I decided to chuck it and go with the alternative, simpler approach. Really liking this system. Simplified things a bit from the example since we only need to show one language at a time. Will need to figure out how to use the same language throughout the program.
Diffstat (limited to 'src')
-rw-r--r--src/I18n.hs27
-rw-r--r--src/Plugin/GitHubCommit.hs4
2 files changed, 12 insertions, 19 deletions
diff --git a/src/I18n.hs b/src/I18n.hs
index 988c823..5a74d80 100644
--- a/src/I18n.hs
+++ b/src/I18n.hs
@@ -1,30 +1,25 @@
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE TemplateHaskell #-}
module I18n
( Locale(..)
- , RenderMessage
+ , Message(..)
- , mkMessage
, translate
) where
import qualified Data.Text as T
-import Text.Shakespeare.I18N (mkMessage, renderMessage, RenderMessage)
-
-data Bot = Bot
-
data Locale = EN | FR
-toISOLocale :: Locale -> T.Text
-toISOLocale EN = "en"
-toISOLocale FR = "fr"
+data Message
+ = GitHubCommitRepoURLNotFound
+ | GitRemoteSetOriginUpdatedRepoURL T.Text
-mkMessage "Bot" "messages" "en"
+translate_en_US :: Message -> T.Text
+translate_en_US GitHubCommitRepoURLNotFound = "I couldn't find a repo URL for \
+ \this channel. Try `git remote set origin REPO_URL`."
+translate_en_US (GitRemoteSetOriginUpdatedRepoURL url) =
+ "I updated the channel's repo URL to '" `T.append` url `T.append` "'."
-translate :: (RenderMessage Bot b) => Locale -> b -> T.Text
-translate locale message =
- renderMessage Bot [(toISOLocale locale)] message
+translate :: Locale -> Message -> T.Text
+translate EN = translate_en_US
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 23de2fa..8b43b57 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -33,9 +33,7 @@ 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 $ translate EN MsgGitHubCommitRepoURLNotFound
+ Left $ translate EN GitHubCommitRepoURLNotFound
respond ((RepoUrlRow r):_) =
Right $ r `T.append` "/commits/" `T.append` T.pack (
M.textStr message =~ matchRegex gitHubCommit)