Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
aa1ab5c7
Commit
aa1ab5c7
authored
11 years ago
by
Ned Batchelder
Browse files
Options
Downloads
Patches
Plain Diff
Use yaml for a civilized config file.
parent
8e707b28
Loading
Loading
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
conf/locale/config
+1
-4
1 addition, 4 deletions
conf/locale/config
conf/locale/config.yaml
+33
-0
33 additions, 0 deletions
conf/locale/config.yaml
i18n/config.py
+15
-20
15 additions, 20 deletions
i18n/config.py
i18n/tests/test_config.py
+1
-1
1 addition, 1 deletion
i18n/tests/test_config.py
with
50 additions
and
25 deletions
conf/locale/config
+
1
−
4
View file @
aa1ab5c7
{
"locales" : ["en"],
"dummy-locale" : "eo"
}
This file is now at config.yaml in the same directory.
This diff is collapsed.
Click to expand it.
conf/locale/config.yaml
0 → 100644
+
33
−
0
View file @
aa1ab5c7
# Configuration for i18n workflow.
locales
:
-
en
-
fr
-
ko_KR
# More languages we might want someday, these have started on Transifex.
# ru
# es_419
# ja_JP
# pt_BR
# zh_CN
# zh_TW
# ar
# es_ES
# fa_IR
# tr_TR
# de_DE
# id
# hi
# vi
# pt_PT
# lt_LT
# gl
# it_IT
# cs
# et_EE
# nb
# sk
# The locale used for fake-accented English, for testing.
dummy-locale
:
eo
This diff is collapsed.
Click to expand it.
i18n/config.py
+
15
−
20
View file @
aa1ab5c7
import
os
import
json
import
yaml
from
path
import
path
# BASE_DIR is the working directory to execute django-admin commands from.
...
...
@@ -16,7 +17,13 @@ class Configuration(object):
# Reads localization configuration in json format
"""
_source_locale
=
'
en
'
DEFAULTS
=
{
'
generate_merge
'
:
{},
'
ignore_dirs
'
:
[],
'
locales
'
:
[
'
en
'
],
'
segment
'
:
{},
'
source_locale
'
:
'
en
'
,
}
def
__init__
(
self
,
filename
):
self
.
_filename
=
filename
...
...
@@ -29,24 +36,12 @@ class Configuration(object):
if
not
os
.
path
.
exists
(
filename
):
raise
Exception
(
"
Configuration file cannot be found: %s
"
%
filename
)
with
open
(
filename
)
as
stream
:
return
json
.
load
(
stream
)
@property
def
locales
(
self
):
"""
Returns a list of locales declared in the configuration file,
e.g. [
'
en
'
,
'
fr
'
,
'
es
'
]
Each locale is a string.
"""
return
self
.
_config
[
'
locales
'
]
return
yaml
.
safe_load
(
stream
)
@property
def
source_locale
(
self
):
"""
Returns source language.
Source language is English.
"""
return
self
.
_source_locale
def
__getattr__
(
self
,
name
):
if
name
in
self
.
DEFAULTS
:
return
self
.
_config
.
get
(
name
,
self
.
DEFAULTS
[
name
])
raise
AttributeError
(
"
Configuration has no such setting: {!r}
"
.
format
(
name
))
@property
def
dummy_locale
(
self
):
...
...
@@ -76,4 +71,4 @@ class Configuration(object):
return
self
.
get_messages_dir
(
self
.
source_locale
)
CONFIGURATION
=
Configuration
(
LOCALE_DIR
.
joinpath
(
'
config
'
).
normpath
())
CONFIGURATION
=
Configuration
(
LOCALE_DIR
.
joinpath
(
'
config
.yaml
'
).
normpath
())
This diff is collapsed.
Click to expand it.
i18n/tests/test_config.py
+
1
−
1
View file @
aa1ab5c7
...
...
@@ -9,7 +9,7 @@ class TestConfiguration(TestCase):
"""
def
test_config
(
self
):
config_filename
=
os
.
path
.
normpath
(
os
.
path
.
join
(
LOCALE_DIR
,
'
config
'
))
config_filename
=
os
.
path
.
normpath
(
os
.
path
.
join
(
LOCALE_DIR
,
'
config
.yaml
'
))
config
=
Configuration
(
config_filename
)
self
.
assertEqual
(
config
.
source_locale
,
'
en
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment