| Class | CommonLabelService |
| In: |
lib/design_api.rb
|
| Parent: | DesignSubService |
book として与えられるデータで po_messages および po_translations を置き換える。
# File lib/design_api.rb, line 653
653: def export(book)
654: hash = Language.to_h
655: mids = []
656: tids = []
657: book.main_sheet.common_labels.each do |common_label|
658: message_class = common_label.type.constantize
659: msgid = common_label.msgid
660: msgid_plural = common_label.msgid_plural
661: msgid_n = common_label.msgid_n
662: po_message = message_class.find_by_msgid(msgid)
663: unless (po_message &&
664: po_message.msgid_plural == msgid_plural &&
665: po_message.msgid_n == msgid_n)
666: # added newly msgid.
667: po_message = message_class.create!(:domain_id => book.client_identifier_y,
668: :msgctxt => "",
669: :msgid => msgid,
670: :msgid_plural => msgid_plural,
671: :msgid_n => msgid_n)
672: end
673: mids << po_message.id
674: # update po_messages.
675: common_label.common_values.each do |value|
676: klass = "PoTranslation#{hash[value.language_id].to_s.camelize}".constantize
677: if po_translation = klass.find_by_po_message_id(po_message.id)
678: # update the existing msgstr.
679: po_translation.msgstr = value.common_value
680: po_translation.save!
681: else
682: # added newly msgstr.
683: po_translation = klass.create!(:domain_id => book.client_identifier_y,
684: :po_message_id => po_message.id,
685: :msgstr => value.common_value)
686: end
687: tids << po_translation.id
688: end
689: end
690: emids = PoMessage.find(:all, :conditions => ["msgctxt <> ?", "Application|"], :order => "id").map(&:id)
691: PoMessage.delete(emids - mids)
692: etids = PoTranslation.find(:all, :conditions => {:po_message_id => emids}, :order => "id").map(&:id)
693: PoTranslation.delete(etids - tids)
694: return PoMessage.to_book.succeed
695: end