Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updating some documentation and also refactoring some things

  • Loading branch information...
commit e2edd16826c5bffab60240d66cc36b39d9a900f0 1 parent a5c3b52
@peburrows authored
Showing with 43 additions and 36 deletions.
  1. +12 −1 README
  2. +31 −35 app/models/translator_tags.rb
View
13 README
@@ -3,7 +3,7 @@
Created By: Phil Burrows, January 2008
peburrows@gmail.com
http://philburrows.com
-http://svn.philburrows.com/radiant-extensions/translator
+http://dev.philburrows.com/svn/radiant-extensions/translator/trunk
-------------------------
@@ -46,3 +46,14 @@ Then, in your layout, simply use the translator tags the same way you would use
<r:translator:content name="sidebar" inherit="true" />
each of these will render the appropriate page part, determined by the browser's Accept-Language
+
+You can also take advantage of the <r:translator:title /> tag which will render the normal page title by default,
+but will first check for a config page part that specifies other titles for the different languages.
+Sample config page part -->
+
+translator:
+ es:
+ title: éste es el título
+ de:
+ title: dieses ist der titel
+
View
66 app/models/translator_tags.rb
@@ -15,14 +15,24 @@ module TranslatorTags
*Usage:*
<pre><code><r:translator:title /></code></pre>
+
+ *Then in a config page part do the following*
+ <pre><code>
+ translator:
+ es:
+ title: éste es el título
+ de:
+ title: dieses ist der titel
+ </pre></code>
}
tag 'translator:title' do |tag|
page = tag.locals.page
title = page.title
- config_content = page.render_part(:translator_config)
+ config_content = page.render_part(:config)
unless config_content.blank?
lang = language(tag)
config = YAML::load(config_content)
+ config = (config.blank? || config['translator'].blank?) ? {} : config['translator']
if config[lang]
config[lang]['title'].blank? ? page.title : config[lang]['title']
else
@@ -48,25 +58,8 @@ module TranslatorTags
}
tag 'translator:content' do |tag|
page = tag.locals.page
- lang = language(tag)
- suffix = lang.blank? ? "" : "_#{lang}"
- # # this is where we need to grab the Accept-Language
- # request = tag.globals.page.request
- # lang = request.env['HTTP_ACCEPT_LANGUAGE']
- #
- # # grab the two letter abbreviation -- some browsers pass multiple languages
- # m = lang.match(/^([a-zA-Z][a-zA-Z])(.)+$/)
- # if m && !request.session[:language]
- # lang = m.captures.first.downcase
- # else
- # # english is set as the default
- # lang = request.session[:language] || "en"
- # end
- #
- # logger.error(request.session)
- #
- # # and now the part's suffix will be determined by the accept-language
- # suffix = lang.match(/^en/i) ? "" : "_#{lang}"
+
+ suffix = suffixize(language(tag))
base_part_name = tag_part_name(tag)
part_name = base_part_name + "#{suffix}"
@@ -104,23 +97,26 @@ module TranslatorTags
def language(tag)
# this is where we need to grab the Accept-Language
- request = tag.globals.page.request
- lang = request.env['HTTP_ACCEPT_LANGUAGE']
+ request = tag.globals.page.request
+ lang = request.env['HTTP_ACCEPT_LANGUAGE']
- # grab the two letter abbreviation -- some browsers pass multiple languages
- m = lang.match(/^([a-zA-Z][a-zA-Z])(.)+$/)
- if m && !request.session[:language]
- lang = m.captures.first.downcase
- else
- # english is set as the default
- lang = request.session[:language] || "en"
- end
-
- logger.error(request.session)
+ # grab the two letter abbreviation -- some browsers pass multiple languages, but we just want the first one (for now)
+ # there's quite a bit more we could do with this, like falling back to the other languages that the user-agent requests
+ # for now, it's a simple hit or miss on the first in the series
+ m = lang.match(/^([a-zA-Z][a-zA-Z])(.)+$/)
+ if m && !request.session[:language]
+ lang = m.captures.first.downcase
+ else
+ # english is set as the default
+ lang = request.session[:language] || "en"
+ end
+
+ # send back the two-letter abbreviation, or a blank string if it's english
+ lang.match(/^en/i) ? "" : lang
+ end
- # and now the part's suffix will be determined by the accept-language
- # suffix = lang.match(/^en/i) ? "" : "_#{lang}"
- lang.match(/^en/i) ? "" : lang
+ def suffixize(lang)
+ lang.blank? ? "" : "_#{lang}"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.