Commit e6febcd3e7ba98e0e6bfc178fe6c10e4d6ab3468
1 parent
46b6c370
Exists in
staging
and in
42 other branches
ActionItem523: adding a terminology backend implementation
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2301 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
59 additions
and
1 deletions
Show diff stats
app/views/shared/user_menu.rhtml
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | 17 | ||
| 18 | <li><a href="<%= homepage_path(:profile => current_user.login) %>" | 18 | <li><a href="<%= homepage_path(:profile => current_user.login) %>" |
| 19 | help="<%= _('Go to your home page.') %>" | 19 | help="<%= _('Go to your home page.') %>" |
| 20 | - ><span class="icon-menu-home"></span><%= _('My Home Page') %></a></li> | 20 | + ><span class="icon-menu-home"></span><%= Noosfero.term(N_('My Home Page')) %></a></li> |
| 21 | 21 | ||
| 22 | <!-- li><a href="#"><span class="icon-menu-blog"></span> Meu Blog</a></li --> | 22 | <!-- li><a href="#"><span class="icon-menu-blog"></span> Meu Blog</a></li --> |
| 23 | 23 |
lib/noosfero.rb
| 1 | +require 'gettext' | ||
| 2 | + | ||
| 1 | module Noosfero | 3 | module Noosfero |
| 2 | PROJECT = 'noosfero' | 4 | PROJECT = 'noosfero' |
| 3 | VERSION = '0.11.0' | 5 | VERSION = '0.11.0' |
| @@ -30,6 +32,16 @@ module Noosfero | @@ -30,6 +32,16 @@ module Noosfero | ||
| 30 | end | 32 | end |
| 31 | end | 33 | end |
| 32 | 34 | ||
| 35 | + def self.term(t) | ||
| 36 | + gettext(self.terminology.get(t)) | ||
| 37 | + end | ||
| 38 | + def self.terminology | ||
| 39 | + @terminology ||= Noosfero::Terminology::Default.new | ||
| 40 | + end | ||
| 41 | + def self.terminology=(term) | ||
| 42 | + @terminology = term | ||
| 43 | + end | ||
| 44 | + | ||
| 33 | end | 45 | end |
| 34 | 46 | ||
| 35 | require 'noosfero/constants' | 47 | require 'noosfero/constants' |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +module Noosfero | ||
| 2 | + class Terminology | ||
| 3 | + | ||
| 4 | + def get(x) | ||
| 5 | + raise NotImplementedError | ||
| 6 | + end | ||
| 7 | + | ||
| 8 | + # the default terminology. Just returns the same message as is. | ||
| 9 | + class Default | ||
| 10 | + def get(x) | ||
| 11 | + x | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + class Custom | ||
| 16 | + def initialize(hash) | ||
| 17 | + @messages = hash | ||
| 18 | + end | ||
| 19 | + def get(x) | ||
| 20 | + @messages[x] || x | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + end | ||
| 25 | +end |
test/unit/noosfero_test.rb
| @@ -31,4 +31,13 @@ class NoosferoTest < Test::Unit::TestCase | @@ -31,4 +31,13 @@ class NoosferoTest < Test::Unit::TestCase | ||
| 31 | assert_match /^#{Noosfero.identifier_format}$/, 'with.dot' | 31 | assert_match /^#{Noosfero.identifier_format}$/, 'with.dot' |
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | + should 'delegate terminology' do | ||
| 35 | + Noosfero.terminology.expects(:get).with('lalala').returns('lelele') | ||
| 36 | + assert_equal 'lelele', Noosfero.term('lalala') | ||
| 37 | + end | ||
| 38 | + | ||
| 39 | + should 'use default terminology by default' do | ||
| 40 | + assert_equal 'lalalalala', Noosfero.term('lalalalala') | ||
| 41 | + end | ||
| 42 | + | ||
| 34 | end | 43 | end |