Merge branch 'master' of github.com:martini/zammad

This commit is contained in:
Roy Kaldung 2013-01-04 15:08:02 +01:00
commit 852e47c474
2 changed files with 47 additions and 0 deletions

View file

@ -1,6 +1,19 @@
class Translation < ApplicationModel
before_create :set_initial
def self.translate(locale, string)
# translate string
record = Translation.where( :locale => locale, :source => string ).first
return record.target if record
# fallback lookup in en
record = Translation.where( :locale => 'en', :source => string ).first
return record.target if record
return string
end
private
def set_initial
self.target_initial = self.target

View file

@ -0,0 +1,34 @@
# encoding: utf-8
require 'test_helper'
class TranslationTest < ActiveSupport::TestCase
test 'translation' do
tests = [
# test 1
{
:lang => 'en',
:string => 'New',
:result => 'New',
},
# test 2
{
:lang => 'de',
:string => 'New',
:result => 'Neu',
},
# test 3
{
:lang => 'de',
:string => 'not translated - lalala',
:result => 'not translated - lalala',
},
]
tests.each { |test|
result = Translation.translate( test[:lang], test[:string] )
assert_equal( result, test[:result], "verify result" )
}
end
end