From 81faf518d6d1ca5c09a00da1907448a84bed1a4b Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Mon, 16 Jan 2012 15:49:01 +0000 Subject: [PATCH] Added language dropdown to the edit form and made sure we display the languages in their native language. Had to apply a language patch to cover those languages not fully specified in babel (like Norsk). --- ckan/lib/helpers.py | 38 +++++++++++++++++++- ckan/logic/schema.py | 1 + ckan/templates/package/new_package_form.html | 10 ++++++ ckan/templates/package/read_core.html | 5 +++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index e61c5ed5f1d..5385685bcde 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -21,7 +21,8 @@ from alphabet_paginate import AlphaPage from lxml.html import fromstring from i18n import get_available_locales - +import babel +from babel import Locale try: @@ -339,3 +340,38 @@ def resource_link(resource_dict, package_id): resource_id=resource_dict['id']) return link_to(text, url) + +language_patches = { + 'ak':u'Akan', + 'ee':u'Eʋegbe', + 'ig':u'Asụsụ Igbo', + 'no':u'Norsk', + 'tg': u'тоҷикӣ, toğikī, تاجیکی‎', + 'tl': u'Wikang Tagalog', + 'ug': u'Uyƣurqə, ئۇيغۇرچە‎', + 'wo': u'Wollof', +} + +def native_name_for_language_code(code): + """ For the given language code make sure we return the name for that + language, in the language we were given. """ + global language_patches + return Locale(code).get_display_name(code) or language_patches.get(code) + +language_codes = [] +ignore_language_codes = ['dv'] +def language_codes_pairs(lang='en'): + """ Return an iterable of tuples which are (nativename, code,) for each + language """ + global language_codes + global language_patches + + if len(language_codes) == 0: + codes = [Locale(x) for x in babel.localedata.list() if len(x) == 2 and not x in ignore_language_codes] + for locale in codes: + if locale.display_name: + language_codes.append( (locale.display_name,locale.language)) + elif locale.language in language_patches: + language_codes.append( (language_patches[locale.language],locale.language) ) + return language_codes + diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py index 9ec6244c3be..7e2b5557078 100644 --- a/ckan/logic/schema.py +++ b/ckan/logic/schema.py @@ -94,6 +94,7 @@ def default_package_schema(): 'maintainer_email': [ignore_missing, unicode], 'license_id': [ignore_missing, unicode], 'notes': [ignore_missing, unicode], + 'language': [ignore_missing, unicode], 'url': [ignore_missing, unicode],#, URL(add_http=False)], 'version': [ignore_missing, unicode, package_version_validator], 'state': [ignore_not_package_admin, ignore_missing], diff --git a/ckan/templates/package/new_package_form.html b/ckan/templates/package/new_package_form.html index 4b76a8f32d8..f304c3bae57 100644 --- a/ckan/templates/package/new_package_form.html +++ b/ckan/templates/package/new_package_form.html @@ -165,6 +165,16 @@

Tags

A number representing the version (if applicable)
e.g. 1.2.0
+
+
+ +
+ +