Skip to content

Commit

Permalink
Localize xblock with vietnamese translations
Browse files Browse the repository at this point in the history
  • Loading branch information
caseylitton committed Jun 15, 2017
1 parent d9b4461 commit 5cf9aa9
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 234 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
.coverage
coverage.xml
.tox/
.DS_STORE
18 changes: 0 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = function (grunt) {
var directoryPublic = directoryPackage + '/public';
var directoryPrivateJsAll = directoryPrivate + '/**/*.js';
var directoryPrivateLessAll = directoryPrivate + '/**/*.less';
var directoryPrivateHtmlAll = directoryPrivate + '/**/*.html';
var directoryPublicCssAll = directoryPublic + '/**/*.css';

grunt.initConfig({
Expand Down Expand Up @@ -71,21 +70,6 @@ module.exports = function (grunt) {
}],
},
},
htmlmin: {
all: {
options: {
removeComments: true,
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
},
files: {
'freetextresponse/public/view.html': directoryPrivate + '/view.html',
},
},
},
jshint: {
options: {
ignores: [
Expand Down Expand Up @@ -154,7 +138,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-htmlmin');

grunt.registerTask('default', [
'jshint',
Expand All @@ -163,6 +146,5 @@ module.exports = function (grunt) {
'less',
'csslint',
'uglify',
'htmlmin',
]);
};
1 change: 1 addition & 0 deletions conf/locale
150 changes: 70 additions & 80 deletions freetextresponse/freetextresponse.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
This is the core logic for the Free-text Response XBlock
"""

import os

import pkg_resources
from django.utils.translation import ungettext
from enum import Enum
from django.template.context import Context
from django.template.loader import get_template
from django.utils.translation import ungettext
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
from xblock.core import XBlock
from xblock.fields import Boolean
from xblock.fields import Float
Expand All @@ -18,9 +18,8 @@
from xblock.validation import ValidationMessage
from xblockutils.studio_editable import StudioEditableXBlockMixin

from .utils import _


@XBlock.needs("i18n")
class FreeTextResponse(StudioEditableXBlockMixin, XBlock):
# pylint: disable=too-many-ancestors, too-many-instance-attributes
"""
Expand Down Expand Up @@ -90,7 +89,7 @@ def workbench_scenarios():
help=_(
'This is the title for this question type'
),
default=_('Free-text Response'),
default='Free-text Response',
scope=Scope.settings,
)
fullcredit_keyphrases = List(
Expand Down Expand Up @@ -149,7 +148,7 @@ def workbench_scenarios():
'This is the prompt students will see when '
'asked to enter their response'
),
default=_('Please enter your response within this text area'),
default='Please enter your response within this text area',
scope=Scope.settings,
multiline_editor=True,
)
Expand All @@ -159,7 +158,7 @@ def workbench_scenarios():
'This is the message students will see upon '
'submitting their response'
),
default=_('Your submission has been received'),
default='Your submission has been received',
scope=Scope.settings,
)
weight = Integer(
Expand All @@ -178,7 +177,7 @@ def workbench_scenarios():
'This is the message students will see upon '
'submitting a draft response'
),
default=_(
default=(
'Your answers have been saved but not graded. '
'Click "Submit" to grade them.'
),
Expand Down Expand Up @@ -211,38 +210,75 @@ def workbench_scenarios():
'fullcredit_keyphrases',
'halfcredit_keyphrases',
'submitted_message',
'saved_message',
)

def build_fragment(
self,
template,
context_dict,
initialize_js_func,
additional_css=[],
additional_js=[],
):
# pylint: disable=dangerous-default-value, too-many-arguments
"""
Creates a fragment for display.
"""
context = Context(context_dict)
fragment = Fragment(template.render(context))
for item in additional_css:
url = self.runtime.local_resource_url(self, item)
fragment.add_css_url(url)
for item in additional_js:
url = self.runtime.local_resource_url(self, item)
fragment.add_javascript_url(url)
fragment.initialize_js(initialize_js_func)
return fragment

# Decorate the view in order to support multiple devices e.g. mobile
# See: https://openedx.atlassian.net/wiki/display/MA/Course+Blocks+API
# section 'View @supports(multi_device) decorator'
@XBlock.supports('multi_device')
def student_view(self, context=None):
# pylint: disable=unused-argument
def student_view(self, context={}):
# pylint: disable=dangerous-default-value
"""The main view of FreeTextResponse, displayed when viewing courses.
The main view which displays the general layout for FreeTextResponse
Args:
context: Not used for this view.
Returns:
(Fragment): The HTML Fragment for this XBlock, which determines the
general frame of the FreeTextResponse Question.
"""
Build the fragment for the default student view
"""
view_html = FreeTextResponse.get_resource_string('view.html')
view_html = view_html.format(
self=self,
word_count_message=self._get_word_count_message(),
indicator_class=self._get_indicator_class(),
problem_progress=self._get_problem_progress(),
used_attempts_feedback=self._get_used_attempts_feedback(),
nodisplay_class=self._get_nodisplay_class(),
visibility_class=self._get_indicator_visibility_class(),
submitted_message='',
user_alert='',

self.runtime.service(self, 'i18n')
context.update(
{
'display_name': self.display_name,
'indicator_class': self._get_indicator_class(),
'nodisplay_class': self._get_nodisplay_class(),
'problem_progress': self._get_problem_progress(),
'prompt': self.prompt,
'student_answer': self.student_answer,
'used_attempts_feedback': self._get_used_attempts_feedback(),
'visibility_class': self._get_indicator_visibility_class(),
'word_count_message': self._get_word_count_message(),
}
)
template = get_template('freetextresponse_view.html')
fragment = self.build_fragment(
html_source=view_html,
paths_css=[
'view.less.min.css',
template,
context,
initialize_js_func='FreeTextResponseView',
additional_css=[
'public/view.less.min.css',
],
paths_js=[
'view.js.min.js',
additional_js=[
'public/view.js.min.js',
],
fragment_js='FreeTextResponseView',
)
return fragment

Expand All @@ -264,7 +300,7 @@ def _generate_validation_message(cls, msg):
"""
result = ValidationMessage(
ValidationMessage.ERROR,
_(unicode(msg))
ugettext(unicode(msg))
)
return result

Expand Down Expand Up @@ -298,51 +334,6 @@ def validate_field_data(self, validation, data):
)
validation.add(msg)

@classmethod
def get_resource_string(cls, path):
"""
Retrieve string contents for the file path
"""
path = os.path.join('public', path)
resource_string = pkg_resources.resource_string(__name__, path)
return resource_string.decode('utf8')

def get_resource_url(self, path):
"""
Retrieve a public URL for the file path
"""
path = os.path.join('public', path)
resource_url = self.runtime.local_resource_url(self, path)
return resource_url

def build_fragment(
self,
html_source=None,
paths_css=[],
paths_js=[],
urls_css=[],
urls_js=[],
fragment_js=None,
):
# pylint: disable=dangerous-default-value, too-many-arguments
"""
Assemble the HTML, JS, and CSS for an XBlock fragment
"""
fragment = Fragment(html_source)
for url in urls_css:
fragment.add_css_url(url)
for path in paths_css:
url = self.get_resource_url(path)
fragment.add_css_url(url)
for url in urls_js:
fragment.add_javascript_url(url)
for path in paths_js:
url = self.get_resource_url(path)
fragment.add_javascript_url(url)
if fragment_js:
fragment.initialize_js(fragment_js)
return fragment

def _get_indicator_visibility_class(self):
"""
Returns the visibility class for the correctness indicator html element
Expand Down Expand Up @@ -379,7 +370,7 @@ def _get_invalid_word_count_message(self, ignore_attempts=False):
(not self._word_count_valid())
):
word_count_message = self._get_word_count_message()
result = _(
result = ugettext(
"Invalid Word Count. {word_count_message}"
).format(
word_count_message=word_count_message,
Expand Down Expand Up @@ -475,7 +466,6 @@ def _compute_score(self):
def _determine_credit(self):
# Not a standard xlbock pylint disable.
# This is a problem with pylint 'enums and R0204 in general'
# pylint: disable=redefined-variable-type
"""
Helper Method that determines the level of credit that
the user should earn based on their answer
Expand Down
Binary file added freetextresponse/locale/vi/LC_MESSAGES/django.mo
Binary file not shown.
48 changes: 48 additions & 0 deletions freetextresponse/locale/vi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Vietnamese Translations for Free Text Response Xblock
# plural translations are copies of the singular version

# Copyright (C) 2017
# This file is distributed under the same license as the free-text-response package.
# Hang Pham <[email protected]>, 2017
#
msgid ""
msgstr ""
"Project-Id-Version: 0.1.2\n"
"Report-Msgid-Bugs-To: mondiaz <[email protected]>\n"
"POT-Creation-Date: 2017-06-13 22:13+0000\n"
"PO-Revision-Date: 2017-06-14 22:13+0000\n"
"Last-Translator: mondiaz <[email protected]>, 2017\n"
"Language-Team: Vietnamese (https://www.transifex.com/stanford-online/teams/22259/vi/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: vi\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: freetextresponse/freetextresponse.py:427
msgid "Your response must be between {min} and {max} word."
msgid_plural "Your response must be between {min} and {max} words."
msgstr[0] "Giới hạn {min}-{max} từ."
msgstr[1] "Giới hạn {min}-{max} từ."

#: freetextresponse/freetextresponse.py:449
msgid "Invalid Word Count. {word_count_message}"
msgstr "Số từ không hợp lệ. {word_count_message}"

#: freetextresponse/freetextresponse.py:502
msgid "{weight} point possible"
msgid_plural "{weight} points possible"
msgstr[0] ""
msgstr[1] ""

#: freetextresponse/freetextresponse.py:515
msgid "{score_string}/{weight} point"
msgid_plural "{score_string}/{weight} points"
msgstr[0] ""
msgstr[1] ""

#: freetextresponse/freetextresponse.py:577
msgid "You have used {count_attempts} of {max_attempts} submission"
msgid_plural "You have used {count_attempts} of {max_attempts} submissions"
msgstr[0] "Bạn đã thử {count_attempts} của {max_attempts} lần"
msgstr[1] "Bạn đã thử {count_attempts} của {max_attempts} lần"
28 changes: 0 additions & 28 deletions freetextresponse/private/view.html

This file was deleted.

Loading

0 comments on commit 5cf9aa9

Please sign in to comment.