forked from OpenNeo/impress
localize blog posts
This commit is contained in:
parent
e71530a958
commit
923335b8da
2 changed files with 36 additions and 2 deletions
|
@ -105,7 +105,10 @@ module ApplicationHelper
|
||||||
current_locale_is_public = false
|
current_locale_is_public = false
|
||||||
options = I18n.public_locales.map do |available_locale|
|
options = I18n.public_locales.map do |available_locale|
|
||||||
current_locale_is_public = true if I18n.locale == available_locale
|
current_locale_is_public = true if I18n.locale == available_locale
|
||||||
[translate('locale_name', :locale => available_locale), available_locale]
|
# Include fallbacks data on the tag. Right now it's used in blog
|
||||||
|
# localization, but may conceivably be used for something else later.
|
||||||
|
[translate('locale_name', :locale => available_locale), available_locale,
|
||||||
|
{'data-fallbacks' => I18n.fallbacks[available_locale].join(',')}]
|
||||||
end
|
end
|
||||||
|
|
||||||
unless current_locale_is_public
|
unless current_locale_is_public
|
||||||
|
|
|
@ -169,11 +169,42 @@ $(function () {
|
||||||
body += '…';
|
body += '…';
|
||||||
}*/
|
}*/
|
||||||
el.find('h2').text(header).wrapInner($('<a/>', {href: url}));
|
el.find('h2').text(header).wrapInner($('<a/>', {href: url}));
|
||||||
el.find('div').html(body);
|
var contentEl = el.find('div');
|
||||||
|
contentEl.html(body);
|
||||||
$('<a/>', {'id': 'blog-preview-comments', href: url + '#disqus_thread'}).appendTo(el);
|
$('<a/>', {'id': 'blog-preview-comments', href: url + '#disqus_thread'}).appendTo(el);
|
||||||
if(image) {
|
if(image) {
|
||||||
el.find('img').attr('src', image).parent().attr('href', url);
|
el.find('img').attr('src', image).parent().attr('href', url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Localize
|
||||||
|
var localizedBodies = {};
|
||||||
|
contentEl.find('.locale').each(function () {
|
||||||
|
var localizedBody = $(this);
|
||||||
|
var locale = localizedBody.attr('class').match(/locale-(\S+)/)[1];
|
||||||
|
localizedBodies[locale] = localizedBody;
|
||||||
|
});
|
||||||
|
|
||||||
|
var fallbacks = $('#locale option:selected').attr('data-fallbacks').split(',');
|
||||||
|
var bestLocale = null;
|
||||||
|
for(var i = 0; i < fallbacks.length; i++) {
|
||||||
|
if(localizedBodies.hasOwnProperty(fallbacks[i])) {
|
||||||
|
bestLocale = fallbacks[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bestLocale) {
|
||||||
|
// I feel bad doing all this in JS rather than CSS, but sometimes you
|
||||||
|
// gotta do what you gotta do if you wanna support any number of locales.
|
||||||
|
for(var locale in localizedBodies) {
|
||||||
|
localizedBodies[locale].hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
localizedBodies[bestLocale].show();
|
||||||
|
|
||||||
|
contentEl.find('.no-locale').hide();
|
||||||
|
}
|
||||||
|
|
||||||
el.fadeIn('medium');
|
el.fadeIn('medium');
|
||||||
addDisqusCount();
|
addDisqusCount();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue