Skip to content

Commit

Permalink
Merge pull request #17 from mogproject/topic-i18n-#15
Browse files Browse the repository at this point in the history
implement i18n (en or ja)
  • Loading branch information
mogproject committed Jul 14, 2015
2 parents 59bbce5 + d000034 commit b379a14
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/easy_alert/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.5'
__version__ = '0.0.6'
19 changes: 18 additions & 1 deletion src/easy_alert/i18n/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
from messages_ja import *
import os
import locale


def __get_locale():
# environment LANG is the first priority
lang = os.environ.get('LANG')
if lang:
return lang.lower()
return locale.getdefaultlocale()[0].lower()


__locale = __get_locale()

if __locale.startswith('ja_'):
from messages_ja import *
else:
from messages_en import *
30 changes: 30 additions & 0 deletions src/easy_alert/i18n/messages_en.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-

EMAIL_ENCODING = 'utf-8'

MSG_DEBUG = u"DEBUG"
MSG_INFO = u"INFO"
MSG_WARN = u"WARN"
MSG_ERROR = u"ERROR"
MSG_CRITICAL = u"CRITICAL"

MSG_PROC_NOT_RUNNING = u'not running'
MSG_PROC_RUNNING = u'%(count)d process(es) are running'
MSG_PROC_STATUS_FORMAT = u'[%(level)s] %(name)s: %(count)s (not "%(condition)s")'
MSG_PROC_ALERT_TITLE = u'Detected Process Abnormality'
MSG_PROC_ALERT = u'Detected the following process abnormality on server \'%(server_id)s\'.\n\n%(result)s\n\n=='

MSG_LOG_SUMMARY = u'[%(tag)s]: %(count)d messages'
MSG_LOG_SNIP = u'(snip)'
MSG_LOG_ALERT_TITLE = u'Detected Error Messages'
MSG_LOG_ALERT = u'Detected the following errors on server \'%(server_id)s\'.\n\n%(result)s\n=='
MSG_LOG_ALERT_PENDING_TITLE = u'Possible Retention of Log Watcher'
MSG_LOG_ALERT_PENDING = u"""Detected the possible retention of Log Watcher on server \'%(server_id)s\'.\n
There exist multiple files which matches the pattern %(pattern)s.\n\n%(paths)s\n
Please check the state of the files, then restart Fluentd or other applications if needed."""

MSG_SSH_STATUS_FORMAT = u'[%(name)s](%(user)s@%(host)s:%(port)d): %(msg)s'
MSG_SSH_ALERT_TITLE = u'Detected SSH Connection Error'
MSG_SSH_ALERT = u'Failed to connect to the following servers using SSH from \'%(server_id)s\'.\n\n%(result)s\n\n=='

MSG_SUBJECT_FORMAT = u'【%(level)s】[%(group_id)s:%(server_id)s] %(title)s (%(start_time)s)'
Empty file.
21 changes: 21 additions & 0 deletions tests/easy_alert/i18n/test_i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
import os


class TestI18N(unittest.TestCase):
def get_email_encoding(self):
import easy_alert

reload(easy_alert.i18n)
return easy_alert.i18n.EMAIL_ENCODING

def test_lang_detection_jp(self):
os.environ['LANG'] = 'ja_JP.UTF-8'
self.assertEqual(self.get_email_encoding(), 'iso-2022-jp')

def test_lang_detection_en(self):
os.environ['LANG'] = 'C'
self.assertEqual(self.get_email_encoding(), 'utf-8')

del os.environ['LANG']
self.assertNotEqual(self.get_email_encoding(), None) # the result depends on the system

0 comments on commit b379a14

Please sign in to comment.