Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick docs intl #3490

Merged
Merged
34 changes: 30 additions & 4 deletions kalite/distributed/management/commands/screenshots.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import errno
#TODO-BLOCKER(MCGallaspy): Better Exception handling in this file.
import glob
import json
import os
import re
from optparse import make_option
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

from django.conf import settings
Expand All @@ -18,7 +16,8 @@

from fle_utils.general import ensure_dir
from kalite.testing.base import KALiteBrowserTestCase
from kalite.testing.mixins import FacilityMixins, BrowserActionMixins
from kalite.testing.mixins.facility_mixins import FacilityMixins
from kalite.testing.mixins.browser_mixins import BrowserActionMixins
from kalite.distributed.management.commands.katest import unregister_distributed_server

USER_TYPE_ADMIN = "admin"
Expand Down Expand Up @@ -56,6 +55,11 @@ class Command(BaseCommand):
dest='no_del',
default=None,
help='Don\'t delete existing screenshots.'),
make_option('--lang',
action='store',
dest='language',
default=None,
help='Specify the language of the session, set by the "set_default_language" api endpoint.'),
)

def handle(self, *args, **options):
Expand Down Expand Up @@ -210,10 +214,32 @@ def __init__(self, *args, **kwargs):
self.browser.set_window_size(1024, 768)
self.browser.implicitly_wait(15)

# After initializing the server (with setUp) and a browser, set the language
self.set_session_language(kwargs['language'])

self.loginfo("==> Browser %s successfully setup with live_server_url %s." %
(self.browser.name, self.live_server_url,))
self.loginfo("==> Saving screenshots to %s ..." % (settings.SCREENSHOTS_OUTPUT_PATH,))


def set_session_language(self, lang_code):
""" Uses the "set_default_language" api endpoint to set the language for the session.
The language pack should already be downloaded, or the behavior is undefined.
TODO: Handle the case when the language pack is not downloaded.

:param lang_code: A string with the language code or None. Value None is a no-op
"""
if not lang_code:
return
self.browser.get(self.live_server_url + reverse("homepage"))
self.browser_wait_for_js_object_exists("$")
data = json.dumps({"lang": lang_code})
self.browser.execute_script("window.SUCCESS=false; $.ajax({type: \"POST\", url: \"%s\", data: '%s', contentType: \"application/json\", success: function(){window.SUCCESS=true}})" % (reverse("set_default_language"), data))
self.browser_wait_for_js_condition("window.SUCCESS")
# Ensure the changes are loaded
self.browser.get(self.live_server_url + reverse("homepage"))


def validate_json_keys(self, shot):
"""
Validates a json item if keys are valid or not, raises an exception if keys are found.
Expand Down
3 changes: 2 additions & 1 deletion kalitectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
] + sys.path
# KALITE_DIR not set, so called from some other source
else:
sys.path = ['python-packages', 'kalite'] + sys.path
filedir = os.path.dirname(__file__)
sys.path = [os.path.join(filedir, 'python-packages'), os.path.join(filedir, 'kalite')] + sys.path


from django.core.management import ManagementUtility, get_commands
Expand Down
11 changes: 10 additions & 1 deletion sphinx-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ Then, install following python packages:
pip install sphinx
```

## Builiding Documentation
## Building Documentation
Change your current working directory to `sphinx-docs` directory under `ka-lite` root and execute following command:
```
make html
```
If the above command executes successfully, docs should be found under `sphinx-docs/_build` directory inside `ka-lite`.

## Building translated docs
1. Make sure you have the sphinx-intl dependency (run the command `pip install -r requirements` in this directory).
2. Extract the translatable messages into pot files using the command `make gettext`. The pot files are then found in `_build/locale directory`.
3. Setup po files for your target language with the command `sphinx-intl update -p _build/locale -l xx`, where xx is the language code of your target language (i.e. "de" or "eo"). (Note: running the `update_pot` command from the central server will generate po files and grab them for uploading.)
4. Translate the po files in `locale/xx/LC_MESSAGES`. TODO: Automate this.
5. Build the mo files with `sphinx-intl build`
6. Make the docs in the target language with the command `make -e SPHINXOPTS="-Dlanguage='xx'" html`
7. Party time!
3 changes: 3 additions & 0 deletions sphinx-docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,6 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}

# sphinx-intl options
locale_dirs = ['locale/']
gettext_compact = False
4 changes: 4 additions & 0 deletions sphinx-docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
sphinx
sphinx-intl
# Required for sphinx-intl in python 2.6
ordereddict
# Required by screenshots.py to take screenshots in headless manner
pyvirtualdisplay
17 changes: 12 additions & 5 deletions sphinx-docs/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
USER_ROLES = ["guest", "coach", "admin", "learner"]
SS_DUMP_DIR = ".screenshot_dump"
OUTPUT_PATH = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), SS_DUMP_DIR))
MANAGE_PATH = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),"..","kalite","manage.py"))
KALITECTL_PATH = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "kalitectl.py"))
# Formatted from subprocess.Popen
# Trying to import call_command to execute a Django mgmt command gets you
# into a weird import hell, probably because of import_all_child_modules...
SCREENSHOT_COMMAND = [sys.executable, MANAGE_PATH, "screenshots"]
SCREENSHOT_COMMAND = [sys.executable, KALITECTL_PATH, "manage", "screenshots"]
SCREENSHOT_COMMAND_OPTS = ["-v", "0", "--output-dir", OUTPUT_PATH]
# These keys are css styles but they need to be camelCased
FOCUS_CSS_STYLES = { "borderStyle": "solid",
Expand All @@ -52,9 +52,17 @@ def purge_screenshots(app, env, docname):
def process_screenshots(app, env):
if not hasattr(env, 'screenshot_all_screenshots'):
return

# Don't bother building screenshots if we're just collecting messages.
# Just checks if we invoked the build command with "gettext" in there somewhere
if "gettext" in sys.argv:
return
all_args = map(lambda x: x['from_str_arg'], env.screenshot_all_screenshots)
subprocess = Popen(SCREENSHOT_COMMAND + SCREENSHOT_COMMAND_OPTS + ["--from-str", json.dumps(all_args)])
# If building in a different language, start the server in a different language
command = SCREENSHOT_COMMAND + SCREENSHOT_COMMAND_OPTS + ["--from-str", json.dumps(all_args)]
language = env.config.language
if language:
command += ["--lang", language]
subprocess = Popen(command)
subprocess.wait()
if display:
display.stop()
Expand Down Expand Up @@ -219,7 +227,6 @@ def run(self):
Build language can be accessed from the BuildEnvironment.
"""
self.env = self.state.document.settings.env
language = self.env.config.language
return_nodes = []
if not hasattr(self.env, 'screenshot_all_screenshots'):
self.env.screenshot_all_screenshots = []
Expand Down