aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2017-08-20 20:17:30 +0200
committerTeddy Wing2017-08-20 20:17:30 +0200
commit37c39d1267e6211233a98081ddea9fef2a6f05df (patch)
tree6964c327d4c45619ea62bec4029a232c2130644a /src
parente1462aecda91b990fe9d2e4531f6986234b84fb4 (diff)
downloadsorbot-37c39d1267e6211233a98081ddea9fef2a6f05df.tar.bz2
GitHubCommit: Make localisation work
Get the language from the command line options and use it to determine which localised string to return on error. Wooo!! it works! So cool. Add French translations for our existing strings. The code to get the language option is pretty messy for the moment. I want to factor it out into its own separate function. But at least it's working now.
Diffstat (limited to 'src')
-rw-r--r--src/I18n.hs8
-rw-r--r--src/Plugin/GitHubCommit.hs15
2 files changed, 19 insertions, 4 deletions
diff --git a/src/I18n.hs b/src/I18n.hs
index e50ba5b..f7a4571 100644
--- a/src/I18n.hs
+++ b/src/I18n.hs
@@ -21,5 +21,13 @@ translate_en_US GitHubCommitRepoURLNotFound = "I couldn't find a repo URL for \
translate_en_US (GitRemoteSetOriginUpdatedRepoURL url) =
"I updated the channel's repo URL to '" `T.append` url `T.append` "'."
+translate_fr_FR :: Message -> T.Text
+translate_fr_FR GitHubCommitRepoURLNotFound = "Je n'ai pas trouvé une URL de \
+ \repo pour ce channel. Essaye `git remote set origin REPO_URL`."
+translate_fr_FR (GitRemoteSetOriginUpdatedRepoURL url) =
+ "J'ai mis à jour l'URL de repo pour ce channel ("
+ `T.append` url `T.append` ")."
+
translate :: Locale -> Message -> T.Text
translate EN = translate_en_US
+translate FR = translate_fr_FR
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 3d2e490..b8ecf9e 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -12,6 +12,7 @@ import Text.Regex.TDFA
import I18n
import qualified Message as M
+import CliOptions (Options(language), parseOptions)
import Plugin.Base
gitHubCommit = defaultPlugin
@@ -32,14 +33,20 @@ gitHubCommitAction message = do
:: IO [RepoUrlRow]
close dbConn
- return $ respond rs
+ opts <- parseOptions
+ let lang = language opts
+
+ return $ respond rs lang
where
- respond [] =
- Left $ translate EN GitHubCommitRepoURLNotFound
- respond ((RepoUrlRow r):_) =
+ respond [] lang =
+ Left $ translate lang GitHubCommitRepoURLNotFound
+ respond ((RepoUrlRow r):_) _ =
Right $ r `T.append` "/commits/" `T.append` T.pack (
M.textStr message =~ matchRegex gitHubCommit)
+-- TODO
+-- lang ::
+
type Id = Int
type RepoUrl = T.Text