Class | MessageService
In: | lib/design_api.rb
Parent: | DesignSubService

Design Web サービスでアプリケーションの多言語対応のための翻訳を扱う API を実装する。

### Methods

export import

### Public Instance methods

export(book)

book として与えられるデータで po_messages および po_translations を置き換える。

[Source]

         # File lib/design_api.rb, line 751
    751:   def export(book)
    752:     hash = Language.to_h
    753:     mids = []
    754:     tids = []
    755:     book.main_sheet.messages.each do |message|
    756:       msgid = message.message_msgid
    757:       po_message = PoMessageSingular.find_by_msgctxt_and_msgid("Application|", msgid)
    758:       unless po_message
    759:         # added newly msgid.
    760:         po_message = PoMessageSingular.create!(:domain_id => book.client_identifier_y,
    761:                                                :msgctxt => "Application|",
    762:                                                :msgid => msgid)
    763:       end
    764:       mids << po_message.id
    765:       # update po_messages.
    766:       message.message_values.each do |value|
    767:         klass = "PoTranslation#{hash[value.language_id].to_s.camelize}".constantize
    768:         if po_translation = klass.find_by_po_message_id(po_message.id)
    769:           # update the existing msgstr.
    770:           po_translation.msgstr = value.message_value
    771:           po_translation.save!
    772:         else
    773:           # added newly msgstr.
    774:           po_translation = klass.create!(:domain_id => book.client_identifier_y,
    775:                                          :po_message_id => po_message.id,
    776:                                          :msgstr => value.message_value)
    777:         end
    778:         tids << po_translation.id
    779:       end
    780:     end
    781:     emids = PoMessageSingular.find(:all, :conditions => {:msgctxt => "Application|"}, :order => "id").map(&:id)
    782:     PoMessageSingular.delete(emids - mids)
    783:     etids = PoTranslation.find(:all, :conditions => {:po_message_id => emids}, :order => "id").map(&:id)
    784:     PoTranslation.delete(etids - tids)
    785:     return PoMessageSingular.to_book.succeed
    786:   end

import(book)

アプリケーションに関する po_messages および po_translations の情報を返す。

[Source]

         # File lib/design_api.rb, line 746
    746:   def import(book)
    747:     return PoMessageSingular.to_book.succeed
    748:   end

[Validate]