Commit aa1ab5c7 by Ned Batchelder

Use yaml for a civilized config file.

parent 8e707b28
{ This file is now at config.yaml in the same directory.
"locales" : ["en"],
"dummy-locale" : "eo"
}
# 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 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())
...@@ -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')
......
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