Commit 07b2473f authored by Yusei Tahara's avatar Yusei Tahara

Commit content translation feature and enable it on Person and GeographicAddress.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30270 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cc21d8c1
......@@ -124,6 +124,25 @@ class Person(XMLObject):
else:
return self.title
security.declareProtected(Permissions.AccessContentsInformation,
'getTranslatedTitle')
def getTranslatedTitle(self, **kw):
"""
Returns the title if it exists or a combination of
first name and last name
"""
if self.title == '':
name_list = []
if self.getTranslatedFirstName(**kw) not in (None, ''):
name_list.append(self.getTranslatedFirstName(**kw))
if self.getTranslatedMiddleName(**kw) not in (None, ''):
name_list.append(self.getTranslatedMiddleName(**kw))
if self.getTranslatedLastName(**kw) not in (None, ''):
name_list.append(self.getTranslatedLastName(**kw))
return ' '.join(name_list)
else:
return self.title
security.declareProtected(Permissions.AccessContentsInformation,
'title_or_id')
def title_or_id(self):
......
......@@ -47,9 +47,12 @@ class AqDynamicInteractor(Interactor):
self.on(TransitionDefinition.setProperties).doAfter(self.resetAqDynamic)
from Products.DCWorkflow.Variables import Variables
self.on(Variables.setStateVar).doAfter(self.resetAqDynamic)
from Products.Localizer.Localizer import Localizer
self.on(Localizer.add_language).doAfter(self.resetAqDynamic)
self.on(Localizer.del_language).doAfter(self.resetAqDynamic)
def resetAqDynamic(self, *args, **kw):
"""
Reset _aq_dynamic
"""
_aq_reset()
\ No newline at end of file
_aq_reset()
......@@ -35,11 +35,17 @@ class GeographicAddress:
{ 'id' : 'street_address',
'description' : 'Street address.',
'type' : 'string',
'mode' : 'w' },
'mode' : 'w',
'translatable': True,
'translation_domain' : 'content_translation',
},
{ 'id' : 'city',
'description' : 'City name.',
'type' : 'string',
'mode' : 'w' },
'mode' : 'w',
'translatable': True,
'translation_domain' : 'content_translation',
},
{ 'id' : 'zip_code',
'description' : 'Zip code.',
'type' : 'string',
......@@ -47,7 +53,10 @@ class GeographicAddress:
{ 'id' : 'prefecture',
'description' : 'Prefecture.',
'type' : 'string',
'mode' : 'w' },
'mode' : 'w',
'translatable': True,
'translation_domain' : 'content_translation',
},
)
_categories = ( 'region', )
......@@ -39,16 +39,22 @@ class Person:
, 'description': 'First name.'
, 'type' : 'string'
, 'mode' : 'w'
, 'translatable' : True
, 'translation_domain' : 'content_translation'
},
{ 'id' : 'last_name'
, 'description': 'Last name.'
, 'type' : 'string'
, 'mode' : 'w'
, 'translatable' : True
, 'translation_domain' : 'content_translation'
},
{ 'id' : 'middle_name'
, 'description': 'Middle name.'
, 'type' : 'string'
, 'mode' : 'w'
, 'translatable' : True
, 'translation_domain' : 'content_translation'
},
{ 'id' : 'birth_name'
, 'description': 'Also called maiden name.'
......@@ -77,6 +83,7 @@ class Person:
, 'type' : 'content'
, 'portal_type' : ( 'Address', )
, 'acquired_property_id' : ( 'text', 'street_address', 'city',
'prefecture',
'zip_code', 'region', 'region_title')
, 'acquisition_copy_value' : 0
, 'acquisition_mask_value' : 1
......@@ -107,6 +114,7 @@ class Person:
, 'type' : 'content'
, 'portal_type' : ( 'Address', )
, 'acquired_property_id' : ( 'text', 'street_address', 'city',
'prefecture',
'zip_code', 'region', 'region_title',
'prefecture')
, 'acquisition_base_category': ( 'subordination', )
......@@ -118,6 +126,8 @@ class Person:
, 'acquisition_depends' : None
, 'alt_accessor_id' : ( 'getCareerDefaultAddressValue', )
, 'mode' : 'w'
, 'translation_acquired_property_id':('street_address', 'city',
'prefecture', )
},
{ 'id' : 'telephone'
, 'storage_id' : 'default_telephone'
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi KK, Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import transaction
class TestContentTranslation(ERP5TypeTestCase):
"""
Test Content Translation
"""
def getTitle(self):
return 'Test Content Translation'
def getBusinessTemplateList(self):
return ('erp5_base',
'erp5_content_translation',
)
def afterSetUp(self):
return
def testContentTranslation(self):
"""
Make sure that translatable properties can have content translation into
the document and read/write translation text by special accessors.
"""
portal = self.portal
person = portal.person_module.newContent(id='yusei',
portal_type='Person',
first_name='Yusei',
last_name='Tahara')
portal.person_module.newContent(id='tarou',
portal_type='Person',
first_name='Tarou',
last_name='Suzuki')
portal.person_module.newContent(id='john',
portal_type='Person',
first_name='John',
last_name='Smith')
transaction.commit()
self.tic()
self.assertEqual(getattr(person, 'setJaKanaTranslatedFirstName', False),
False)
self.assertEqual(getattr(person, 'getJaKanaTranslatedFirstName', False),
False)
self.assert_(getattr(person, 'getEnTranslatedFirstName', False))
self.assert_(getattr(person, 'getEnTranslatedFirstName', False))
portal.Localizer._add_user_defined_language('Japanese Kana', 'ja-kana')
portal.Localizer.add_language('ja-kana')
transaction.commit()
self.tic()
self.assert_(getattr(person, 'setJaKanaTranslatedFirstName', False))
self.assert_(getattr(person, 'getJaKanaTranslatedFirstName', False))
person.setJaKanaTranslatedFirstName('タハラ')
person.setJaKanaTranslatedLastName('ユウセイ')
transaction.commit()
self.tic()
self.assert_('タハラ' in person.Base_viewContentTranslation())
self.assert_('ユウセイ' in person.Base_viewContentTranslation())
self.assertEqual(person.getJaKanaTranslatedFirstName(), 'タハラ')
self.assertEqual(person.getJaKanaTranslatedLastName(), 'ユウセイ')
self.assertEqual(person.getTranslatedTitle(language='ja-kana'),
'タハラ ユウセイ')
# check with acquisition
self.assertEquals(person.getAddress(), None)
person.setDefaultAddressStreetAddress('Taito-ku Tokyo')
self.assertEquals(person.getDefaultAddressStreetAddress(), 'Taito-ku Tokyo')
person.setDefaultAddressJaKanaTranslatedStreetAddress('東京都 台東区')
self.assertEquals(person.getDefaultAddressJaKanaTranslatedStreetAddress(), '東京都 台東区')
self.assertEquals(person.getDefaultAddressTranslatedStreetAddress(language='ja-kana'), '東京都 台東区')
# check acquired target
address = person.getDefaultAddress()
self.assertEquals(address.getStreetAddress(), 'Taito-ku Tokyo')
self.assertEquals(address.getJaKanaTranslatedStreetAddress(), '東京都 台東区')
self.assertEquals(address.getTranslatedStreetAddress(language='ja-kana'), '東京都 台東区')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestContentTranslation))
return suite
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment