Skip to content

Commit

Permalink
Added language dropdown to the edit form and made sure we display the…
Browse files Browse the repository at this point in the history
… languages in their native language.

Had to apply a language patch to cover those languages not fully specified in babel (like Norsk).
  • Loading branch information
rossjones committed Jan 16, 2012
1 parent ff38996 commit 81faf51
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
38 changes: 37 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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

1 change: 1 addition & 0 deletions ckan/logic/schema.py
Expand Up @@ -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],
Expand Down
10 changes: 10 additions & 0 deletions ckan/templates/package/new_package_form.html
Expand Up @@ -165,6 +165,16 @@ <h3>Tags</h3>
<dd class="instructions basic">A number representing the version (if applicable)</dd>
<dd class="hints">e.g. 1.2.0</dd>

<dt><label class="field_opt" for="language">Language</label></dt>
<dd>
<select id="language" name="language">
<py:for each="language_name, language_code in h.language_codes_pairs()">
<option value="${language_code}" py:attrs="{'selected': 'selected' if data.get('language', '') == language_code else None}" >${language_name}</option>
</py:for>
</select>
</dd>


<dt py:if="c.is_sysadmin or c.auth_for_change_state"><label class="field_opt" for="state">State</label></dt>
<dd py:if="c.is_sysadmin or c.auth_for_change_state">
<select id="state" name="state" >
Expand Down
5 changes: 5 additions & 0 deletions ckan/templates/package/read_core.html
Expand Up @@ -75,6 +75,11 @@ <h3>Additional Information</h3>
<td class="dataset-details">${c.pkg.version}</td>
</tr>

<tr py:if="c.pkg.language">
<td class="dataset-label">Language</td>
<td class="dataset-details">${h.native_name_for_language_code(c.pkg.language)}</td>
</tr>

<tr py:if="c.eu_country">
<td class="dataset-label">Country</td>
<td class="dataset-details">${h.code_to_country(c.eu_country)}</td>
Expand Down

0 comments on commit 81faf51

Please sign in to comment.