Commit aa1ab5c7 by Ned Batchelder

Use yaml for a civilized config file.

parent 8e707b28
{
"locales" : ["en"],
"dummy-locale" : "eo"
}
This file is now at config.yaml in the same directory.
# 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
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())
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment