'From etoys2.2 of 27 September 2007 [latest update: #1680] on 3 October 2007 at 12:44:52 pm'! "Change Set: sortedPObyCategory-tak Date: 3 October 2007 Author: Takashi Yamamiya Sort PO file entries by class categories -> class -> methods -> msgid (alphabetical) "! TestCase subclass: #GettextTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Multilingual-Editor'! !GetTextExporter2 methodsFor: 'private' stamp: 'tak 10/3/2007 12:43'! exportBody: literals translator: translator "Export a gettext file body. literals is a dictionary of keyword -> #(MethodReference...) in the textDomain." | sorted msgid sortedMethods category sortKey comment triplets | "Build {sortKey. comment. msgid } to optimize sorting (getting category is too slow). If there are two or more methods for a mgsid, only first method (alphabetical) is used for sorting." triplets := literals associations collect: [:assoc | msgid := assoc key. sortedMethods := assoc value asArray sort. category := (Smalltalk at: sortedMethods first classSymbol) category asString. sortKey := category , ',' , sortedMethods first printString , ',' , msgid. comment := (sortedMethods collect: [:each | each actualClass asString , '>>' , each methodSymbol asString]) inject: category into: [:result :methodName | result , ',' , methodName]. Array with: sortKey with: comment with: msgid]. "Sort and output the words" sorted := triplets sort: [:a :b | a first <= b first]. sorted do: [:triplet | comment := triplet second. msgid := triplet third. self exportRecordHeader: comment. self exportPhrase: msgid translation: (translator ifNil: [''] ifNotNil: [translator translations at: msgid ifAbsent: ''])]! ! !GettextTest methodsFor: 'testing' stamp: 'tak 10/3/2007 12:03'! testExportBody "self debug: #testExportBody" | literals exporter | literals := Dictionary new. literals at: 'key1' put: {MethodReference new setStandardClass: Object methodSymbol: #method1. MethodReference new setStandardClass: Morph methodSymbol: #method2}. exporter := GetTextExporter2 new. exporter stream: '' writeStream. exporter exportBody: literals translator: nil. self assert: exporter stream contents = '#: Morphic-Kernel,Morph>>method2,Object>>method1 msgid "key1" msgstr "" '. literals at: 'key3' put: {MethodReference new setStandardClass: Morph methodSymbol: #another}. literals at: 'key2' put: {MethodReference new setStandardClass: Morph methodSymbol: #another}. exporter stream: '' writeStream. exporter exportBody: literals translator: nil. self assert: exporter stream contents = '#: Morphic-Kernel,Morph>>another msgid "key2" msgstr "" #: Morphic-Kernel,Morph>>another msgid "key3" msgstr "" #: Morphic-Kernel,Morph>>method2,Object>>method1 msgid "key1" msgstr "" '. literals at: 'key4' put: {MethodReference new setStandardClass: LayoutPolicy methodSymbol: #test}. exporter stream: '' writeStream. exporter exportBody: literals translator: nil. self assert: exporter stream contents = '#: Morphic-Kernel,Morph>>another msgid "key2" msgstr "" #: Morphic-Kernel,Morph>>another msgid "key3" msgstr "" #: Morphic-Kernel,Morph>>method2,Object>>method1 msgid "key1" msgstr "" #: Morphic-Layouts,LayoutPolicy>>test msgid "key4" msgstr "" '. ! !