Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
aa1ab5c7
Commit
aa1ab5c7
authored
Jan 20, 2014
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use yaml for a civilized config file.
parent
8e707b28
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
25 deletions
+50
-25
conf/locale/config
+1
-4
conf/locale/config.yaml
+33
-0
i18n/config.py
+15
-20
i18n/tests/test_config.py
+1
-1
No files found.
conf/locale/config
View file @
aa1ab5c7
{
This file is now at config.yaml in the same directory.
"locales" : ["en"],
"dummy-locale" : "eo"
}
conf/locale/config.yaml
0 → 100644
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
i18n/config.py
View file @
aa1ab5c7
import
os
import
os
import
json
import
yaml
from
path
import
path
from
path
import
path
# BASE_DIR is the working directory to execute django-admin commands from.
# BASE_DIR is the working directory to execute django-admin commands from.
...
@@ -16,7 +17,13 @@ class Configuration(object):
...
@@ -16,7 +17,13 @@ class Configuration(object):
# Reads localization configuration in json format
# Reads localization configuration in json format
"""
"""
_source_locale
=
'en'
DEFAULTS
=
{
'generate_merge'
:
{},
'ignore_dirs'
:
[],
'locales'
:
[
'en'
],
'segment'
:
{},
'source_locale'
:
'en'
,
}
def
__init__
(
self
,
filename
):
def
__init__
(
self
,
filename
):
self
.
_filename
=
filename
self
.
_filename
=
filename
...
@@ -29,24 +36,12 @@ class Configuration(object):
...
@@ -29,24 +36,12 @@ class Configuration(object):
if
not
os
.
path
.
exists
(
filename
):
if
not
os
.
path
.
exists
(
filename
):
raise
Exception
(
"Configuration file cannot be found:
%
s"
%
filename
)
raise
Exception
(
"Configuration file cannot be found:
%
s"
%
filename
)
with
open
(
filename
)
as
stream
:
with
open
(
filename
)
as
stream
:
return
json
.
load
(
stream
)
return
yaml
.
safe_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'
]
@property
def
__getattr__
(
self
,
name
):
def
source_locale
(
self
):
if
name
in
self
.
DEFAULTS
:
"""
return
self
.
_config
.
get
(
name
,
self
.
DEFAULTS
[
name
])
Returns source language.
raise
AttributeError
(
"Configuration has no such setting: {!r}"
.
format
(
name
))
Source language is English.
"""
return
self
.
_source_locale
@property
@property
def
dummy_locale
(
self
):
def
dummy_locale
(
self
):
...
@@ -76,4 +71,4 @@ class Configuration(object):
...
@@ -76,4 +71,4 @@ class Configuration(object):
return
self
.
get_messages_dir
(
self
.
source_locale
)
return
self
.
get_messages_dir
(
self
.
source_locale
)
CONFIGURATION
=
Configuration
(
LOCALE_DIR
.
joinpath
(
'config'
)
.
normpath
())
CONFIGURATION
=
Configuration
(
LOCALE_DIR
.
joinpath
(
'config
.yaml
'
)
.
normpath
())
i18n/tests/test_config.py
View file @
aa1ab5c7
...
@@ -9,7 +9,7 @@ class TestConfiguration(TestCase):
...
@@ -9,7 +9,7 @@ class TestConfiguration(TestCase):
"""
"""
def
test_config
(
self
):
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
)
config
=
Configuration
(
config_filename
)
self
.
assertEqual
(
config
.
source_locale
,
'en'
)
self
.
assertEqual
(
config
.
source_locale
,
'en'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment