Skip to content

Commit

Permalink
Multi language support (#262)
Browse files Browse the repository at this point in the history
This pull request adds multi-language support #251. It does this via tornado.locale using the load_translations with files of the form LOCALE.csv, e.g. es_LA.csv. According to the documentation, it would use the browser's locale by default and offer the closest matching locale. I created some translations via Google Translate as a starting point / example, located in the locale folder.

If the player wants to force a translation, they can specify "force_locale" in the configuration file to specify a locale file under the locale directory (force_locale="es_LA").
  • Loading branch information
eljeffeg authored Aug 20, 2019
1 parent 4545e24 commit 27dd26c
Show file tree
Hide file tree
Showing 89 changed files with 8,726 additions and 1,390 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ files/*.cfg
#Alembic
alembic/alembic.ini

#Locale
locale/.~*

# Packages
*.egg
*.egg-info
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Additional platform [screenshots](https://github.com/moloch--/RootTheBox/wiki/Sc
- Optional [in-game Botnets](https://github.com/moloch--/RootTheBox/wiki/Features) or wall of sheep displaying cracked passwords
- Unlocks and upgrades as users capture flags
- Export and share Boxes/Flags
- Multiple Language Support
- Site Themes and other cool stuff

## Setup
Expand Down
10 changes: 10 additions & 0 deletions handlers/BaseHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from tornado import locale
from tornado.web import RequestHandler
from tornado.ioloop import IOLoop
from tornado.websocket import WebSocketHandler
Expand Down Expand Up @@ -244,6 +245,15 @@ def timer(self):
timer = str(timerdiff)
return timer

def get_user_locale(self):
"""
Get user lang value from config.
If None is returned, Tornado fall back to get_browser_locale()
"""
if len(self.config.force_locale) > 0:
return locale.get(self.config.force_locale)
return None


class BaseWebSocketHandler(WebSocketHandler):

Expand Down
25 changes: 15 additions & 10 deletions handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,27 @@


import sys
import tornado.locale

from setup import __version__
from os import urandom, _exit, path as os_path
from tornado import netutil, locale
from tornado.web import Application
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop, PeriodicCallback
from tornado.options import options
from sqlalchemy.exc import OperationalError
from alembic.config import Config, command
from builtins import str

from modules.Menu import Menu
from modules.Recaptcha import Recaptcha
from modules.AppTheme import AppTheme
from libs.ConsoleColors import *
from libs.Scoreboard import Scoreboard, score_bots
from libs.GameHistory import GameHistory
from tornado import netutil
from tornado.web import Application
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop, PeriodicCallback
from sqlalchemy.exc import OperationalError
from libs.DatabaseConnection import DatabaseConnection
from libs.StringCoding import encode
from handlers.BotnetHandlers import *
from handlers.UserHandlers import *
from handlers.AdminHandlers import *
Expand All @@ -55,11 +62,7 @@
from handlers.MaterialsHandler import *
from handlers.ChefHandler import *
from handlers.StaticFileHandler import StaticFileHandler
from alembic.config import Config, command
from libs.DatabaseConnection import DatabaseConnection
from libs.StringCoding import encode
from builtins import str
from tornado.options import options


try:
from urllib.parse import unquote_plus
Expand Down Expand Up @@ -266,6 +269,8 @@ def start_server():
logging.warn(
"%sDebug mode is enabled; DO NOT USE THIS IN PRODUCTION%s" % (bold + R, W)
)
locale.set_default_locale("en_US")
locale.load_translations("locale")
if options.autostart_game:
logging.info("The game is about to begin, good hunting!")
app.settings["history_callback"].start()
Expand Down
664 changes: 664 additions & 0 deletions locale/ar_SA.csv

Large diffs are not rendered by default.

664 changes: 664 additions & 0 deletions locale/bn_BD.csv

Large diffs are not rendered by default.

664 changes: 664 additions & 0 deletions locale/de_DE.csv

Large diffs are not rendered by default.

664 changes: 664 additions & 0 deletions locale/es_LA.csv

Large diffs are not rendered by default.

664 changes: 664 additions & 0 deletions locale/fr_FR.csv

Large diffs are not rendered by default.

664 changes: 664 additions & 0 deletions locale/hi_IN.csv

Large diffs are not rendered by default.

663 changes: 663 additions & 0 deletions locale/ja_JA.csv

Large diffs are not rendered by default.

663 changes: 663 additions & 0 deletions locale/ko_KR.csv

Large diffs are not rendered by default.

663 changes: 663 additions & 0 deletions locale/pt_PT.csv

Large diffs are not rendered by default.

664 changes: 664 additions & 0 deletions locale/ru_RU.csv

Large diffs are not rendered by default.

Loading

0 comments on commit 27dd26c

Please sign in to comment.