'From etoys2.2 of 22 September 2007 [latest update: #1730] on 28 October 2007 at 9:42:28 pm'! "Change Set: transNoopAll-KR Date: 28 October 2007 Author: Korakurider GetTextExporter2 extracts receivers of #translatedNoopAll including arrayed symbols"! !Object methodsFor: 'translating' stamp: 'KR 10/28/2007 15:30'! literalStringsAndSymbolsDo: aBlock "Assuming the receiver receiver is a literal, evaluate aBlock with all Strings (including Symbols) within it." ^ self! ! !Object methodsFor: 'translating' stamp: 'KR 10/28/2007 15:28'! translatedNoopAll "This is correspondence gettext_noop() in gettext. the receiver including arrayed symbols will be extracted into POs and translated" ! ! !Array methodsFor: 'translating' stamp: 'KR 10/28/2007 15:31'! literalStringsAndSymbolsDo: aBlock "Assuming the receiver receiver is a literal, evaluate aBlock with all Strings (including Symbols) within it." self do: [:each | each literalStringsAndSymbolsDo: aBlock]! ! !Array methodsFor: 'translating' stamp: 'KR 10/28/2007 15:28'! translatedNoopAll "This is correspondence gettext_noop() in gettext. the receiver including arrayed symbols will be extracted into POs and translated" ^ self! ! !GetTextExporter2 methodsFor: 'exporting' stamp: 'KR 10/28/2007 21:36'! appendTranslations: domains self appendStringReceivers: #translated into: domains includingSymbols: false. self appendStringReceivers: #translatedNoop into: domains includingSymbols: false. self appendStringReceivers: #translatedNoopAll into: domains includingSymbols: true. self appendVocabularies: domains. ! ! !GetTextExporter2 methodsFor: 'private' stamp: 'KR 10/28/2007 21:35'! appendStringReceivers: aSymbol into: domains includingSymbols: bool | literals references domainName methodReference keywords found | found := TranslatedReceiverFinder new stringReceiversWithContext: aSymbol includingSymbols: bool. found do: [ :assoc | methodReference := assoc key. keywords := assoc value. domainName _ self getTextDomainForClassCategory: (Smalltalk at: methodReference classSymbol) category. literals _ domains at: domainName ifAbsentPut: [Dictionary new]. keywords do: [ :literal | references _ literals at: literal ifAbsentPut: [OrderedCollection new]. references add: methodReference. ]. ]. ! ! !LanguageEditorTest methodsFor: 'testing' stamp: 'KR 10/28/2007 21:31'! testFindTranslatedWords "self debug: #testFindTranslatedWords" | message words | message := MethodReference new setStandardClass: self class methodSymbol: #translatedFinderExample. words := TranslatedReceiverFinder new findWordsWith: #findme in: message includingSymbols: false. self assert: (words includes: 'normal'). self assert: (words includes: 'inside in an array'). self assert: (words includes: 'nested array'). self assert: (words includes: 'nested array again'). self assert: (words includes: 'shouldBeIgnored') not. "Maybe you don't need a symbol" self assert: (words includes: 'symbol') not. self assert: (words includes: 'allSymbol') not. self assert: (words includes: 'allSymbolAgain') not. "Test another findring method to including symbols" words := TranslatedReceiverFinder new findWordsWith: #findme in: message includingSymbols: true. self assert: (words includes: 'normal'). self assert: (words includes: 'inside in an array'). self assert: (words includes: 'nested array'). self assert: (words includes: 'nested array again'). self assert: (words includes: 'shouldBeIgnored'). self assert: (words includes: 'symbol'). self assert: (words includes: 'allSymbol'). self assert: (words includes: 'allSymbolAgain'). ! ! !String methodsFor: 'translating' stamp: 'KR 10/28/2007 15:32'! literalStringsAndSymbolsDo: aBlock "Assuming the receiver receiver is a literal, evaluate aBlock with all Strings (including Symbols) within it." aBlock value: self! ! !String methodsFor: 'translating' stamp: 'KR 10/28/2007 15:28'! translatedNoopAll "This is correspondence gettext_noop() in gettext. the receiver including arrayed symbols will be extracted into POs and translated" ^ self! ! !Symbol methodsFor: 'translating' stamp: 'KR 10/28/2007 15:34'! literalStringsAndSymbolsDo: aBlock "Assuming the receiver receiver is a literal, evaluate aBlock with all Strings (including Symbols) within it." aBlock value: self! ! !TranslatedReceiverFinder methodsFor: 'accessing' stamp: 'KR 10/28/2007 21:23'! findWordsWith: aSymbol in: aMethodReference includingSymbols: bool "Find words for translation with the symbol in a method. See LanguageEditorTest >>testFindTranslatedWords" "| message | message := MethodReference new setStandardClass: Morph class methodSymbol: #supplementaryPartsDescriptions. self new findWordsWIth: #translatedNoop in: message" | messages keywords aParseNode | aParseNode := aMethodReference decompile. "Find from string literal" messages := Set new. self search: aSymbol messageNode: aParseNode addTo: messages. keywords := OrderedCollection new. messages select: [:aMessageNode | aMessageNode receiver isMemberOf: LiteralNode] thenDo: [:aMessageNode | bool ifTrue: [ aMessageNode receiver key literalStringsAndSymbolsDo: [:literal | keywords add: literal]] ifFalse: [aMessageNode receiver key literalStringsDo: [:literal | keywords add: literal]]. ]. "Find from array literal" self arraySearch: aSymbol messageNode: aParseNode addTo: keywords. ^keywords! ! !TranslatedReceiverFinder methodsFor: 'accessing' stamp: 'KR 10/28/2007 21:34'! stringReceiversWithContext: aSymbol includingSymbols: bool "Find string receivers for a symbol. Answer a collection of aMethodReference -> {keyword. keyword...}" "self new stringReceiversWithContext: #translated" | keywords methodReferences | methodReferences _ SystemNavigation default allCallsOn: aSymbol. ^ methodReferences inject: OrderedCollection new into: [:list :next | keywords := self findWordsWith: aSymbol in: next includingSymbols: bool. keywords ifNotEmpty: [list add: next -> keywords]. list] ! ! Object removeSelector: #literalAllStringsDo:!