Пример #1
0
 def test_i18n(self):
     from camelot.model.i18n import Translation, ExportAsPO
     session = Session()
     session.execute(Translation.__table__.delete())
     self.assertEqual(Translation.translate('bucket', 'nl_BE'), None)
     # run twice to check all branches in the code
     Translation.translate_or_register('bucket', 'nl_BE')
     Translation.translate_or_register('bucket', 'nl_BE')
     self.assertEqual(Translation.translate('bucket', 'nl_BE'), 'bucket')
     self.assertEqual(Translation.translate('', 'nl_BE'), '')
     self.assertEqual(Translation.translate_or_register('', 'nl_BE'), '')
     # clear the cache
     Translation._cache.clear()
     # fill the cache again
     translation = Translation(language='nl_BE',
                               source='bucket',
                               value='emmer',
                               uid=1)
     orm.object_session(translation).flush()
     self.assertEqual(Translation.translate('bucket', 'nl_BE'), 'emmer')
     export_action = ExportAsPO()
     model_context = MockModelContext()
     model_context.obj = translation
     try:
         generator = export_action.model_run(model_context)
         file_step = generator.next()
         generator.send(['/tmp/test.po'])
     except StopIteration:
         pass
Пример #2
0
 def update_translation_table():
     from camelot.model.i18n import Translation
     from sqlalchemy.orm.session import Session
     t = Translation.get_by(source=source, language=language)
     if not t:
         t = Translation(source=source, language=language)
     t.value = value
     Session.object_session( t ).flush( [t] )
Пример #3
0
 def update_translation_table():
     from camelot.model.i18n import Translation
     from sqlalchemy.orm.session import Session
     t = Translation.get_by(source=source, language=language)
     if not t:
         t = Translation(source=source, language=language)
     t.value = value
     Session.object_session( t ).flush( [t] )
Пример #4
0
 def test_i18n( self ):
     from camelot.model.i18n import Translation, ExportAsPO
     session = Session()
     session.execute( Translation.__table__.delete() )
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), None )
     # run twice to check all branches in the code
     Translation.translate_or_register( 'bucket', 'nl_BE' )
     Translation.translate_or_register( 'bucket', 'nl_BE' )
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), 'bucket' )
     self.assertEqual( Translation.translate( '', 'nl_BE' ), '' )
     self.assertEqual( Translation.translate_or_register( '', 'nl_BE' ), '' )
     # clear the cache
     Translation._cache.clear()
     # fill the cache again
     translation = Translation( language = 'nl_BE', source = 'bucket',
                                value = 'emmer', uid=1 )
     orm.object_session( translation ).flush()
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), 'emmer' )
     export_action = ExportAsPO()
     model_context = MockModelContext()
     model_context.obj = translation
     try:
         generator = export_action.model_run( model_context )
         file_step = generator.next()
         generator.send( ['/tmp/test.po'] )
     except StopIteration:
         pass