diff options
Diffstat (limited to 'babel/localedata.py')
-rw-r--r-- | babel/localedata.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/babel/localedata.py b/babel/localedata.py index 2a8c442..03381e2 100644 --- a/babel/localedata.py +++ b/babel/localedata.py @@ -57,13 +57,24 @@ def locale_identifiers(): """Return a list of all locale identifiers for which locale data is available. + This data is cached after the first invocation in `locale_identifiers.cache`. + + Removing the `locale_identifiers.cache` attribute or setting it to `None` + will cause this function to re-read the list from disk. + .. versionadded:: 0.8.1 :return: a list of locale identifiers (strings) """ - return [stem for stem, extension in [ - os.path.splitext(filename) for filename in os.listdir(_dirname) - ] if extension == '.dat' and stem != 'root'] + data = getattr(locale_identifiers, 'cache', None) + if data is None: + locale_identifiers.cache = data = [ + stem + for stem, extension in + (os.path.splitext(filename) for filename in os.listdir(_dirname)) + if extension == '.dat' and stem != 'root' + ] + return data def load(name, merge_inherited=True): |