-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1370 from SeasideSt/1369-WAGettextExporter-catalo…
…g-generation-issues Fix for issue #1369 (improvements for WAGettextExporter)
- Loading branch information
Showing
21 changed files
with
153 additions
and
108 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
.../Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/class/newForRBEnvironment..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
instance creation | ||
newForRBEnvironment: aRBEnvironment | ||
^ self new rbEnvironment: aRBEnvironment |
33 changes: 13 additions & 20 deletions
33
...ide-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/createAndSortTriplets..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
exporting | ||
createAndSortTriplets: translationLiterals | ||
|
||
| msgid sortedMethods category sortKey comment commentUnderLined triplets | | ||
triplets := translationLiterals associations | ||
collect: [:assoc | | ||
msgid := assoc key. | ||
sortedMethods := assoc value asArray sort. | ||
category := (Smalltalk at: sortedMethods first instanceSideParentName) category asString. | ||
sortKey := category , ',' , sortedMethods first printString , ',' , msgid. | ||
comment := (sortedMethods | ||
collect: [:each | each actualClass asString , '>>' , each selector asString]) | ||
inject: category | ||
into: [:result :methodName | result , ',' , methodName]. | ||
"Replace white spaces to := because gettext tool might | ||
replace a space to a new line some times, and it makes | ||
difficult to take a diff." | ||
commentUnderLined := comment copyReplaceAll: ' ' with: ':='. | ||
Array | ||
with: sortKey | ||
with: commentUnderLined | ||
with: msgid]. | ||
| msgid sortedMethods sortKey comment commentUnderLined triplets | | ||
triplets := translationLiterals associations collect: [ :assoc | | ||
msgid := assoc key. | ||
sortedMethods := assoc value asArray sort. | ||
sortKey := sortedMethods first printString , ',', msgid. | ||
comment := String streamContents:[ :str | | ||
sortedMethods | ||
do: [ :each | str nextPutAll: each actualClass asString ; nextPutAll: '>>'; nextPutAll: each selector asString ] | ||
separatedBy: [ str nextPut: $, ] ]. | ||
"Replace white spaces to := because gettext tool might replace a space to a new line some times, and it makes difficult to take a diff." | ||
commentUnderLined := comment copyReplaceAll: ' ' with: ':='. | ||
Array with: sortKey with: commentUnderLined with: msgid ]. | ||
|
||
^ triplets sort: [ :a :b | a first <= b first ]. | ||
^ triplets sort: [ :a :b | a first <= b first ] |
14 changes: 14 additions & 0 deletions
14
...tory/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/createHeaders.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
private | ||
createHeaders | ||
| headers | | ||
headers := OrderedCollection new. | ||
headers add: 'Project-Id-Version' -> 'Pharo'. | ||
headers add: 'POT-Creation-Date' -> self currentDateAndTime. | ||
headers add: 'PO-Revision-Date' -> self currentDateAndTime. | ||
headers add: 'Last-Translator' -> ''. | ||
headers add: 'Language-Team' -> ''. | ||
headers add: 'MIME-Version' -> '1.0'. | ||
headers add: 'Content-Type' -> ('text/plain; charset=utf-8'). | ||
headers add: 'Content-Transfer-Encoding' -> '8bit'. | ||
headers add: 'X-Pharo-SystemVersion' -> SystemVersion current asString. | ||
^ headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/currentDateAndTime.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
private | ||
currentDateAndTime | ||
^ String | ||
streamContents: [ :aStream | | ||
aStream nextPutAll: Date today yyyymmdd; | ||
space. | ||
Time now | ||
print24: true | ||
showSeconds: false | ||
on: aStream. | ||
aStream nextPutAll: '-0000' ] |
14 changes: 8 additions & 6 deletions
14
...tory/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/exportCatalog.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
exporting | ||
exportCatalog | ||
"WAGetTextExporter new exportTemplate" | ||
| translationLiterals | "translationLiterals is a dictionary of keyword ->#(MethodReference...)." | ||
exportCatalog | ||
|
||
| translationLiterals | | ||
translationLiterals := self gatherTranslations. | ||
[stream := exportFile asFileReference ensureDelete; writeStream. | ||
self exportLiteralsDict: translationLiterals] | ||
ensure: [stream close] | ||
[ | ||
stream := exportFile asFileReference ensureDelete; writeStream. | ||
self exportHeader. | ||
self exportLiteralsDict: translationLiterals | ||
] ensure: [ stream close ] |
9 changes: 9 additions & 0 deletions
9
...itory/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/exportHeader.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exporting | ||
exportHeader | ||
|
||
| headers | | ||
self exportTag: 'msgid' msg: ''. | ||
self exportTag: 'msgstr' msg: ''. | ||
headers := self createHeaders. | ||
headers do: [ :each | self exportHeaderLineKey: each key value: each value ]. | ||
stream lf; lf |
11 changes: 11 additions & 0 deletions
11
...Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/exportHeaderLineKey.value..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
exporting | ||
exportHeaderLineKey: keyString value: valueString | ||
|
||
stream nextPut: $"; | ||
nextPutAll: keyString; | ||
nextPut: $:; | ||
space; | ||
nextPutAll: valueString; | ||
nextPutAll: '\n'; | ||
nextPut: $"; | ||
lf. |
2 changes: 1 addition & 1 deletion
2
...tory/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/formatString..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
formatting | ||
private | ||
formatString: aString | ||
|
||
| result replacements | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ory/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/rbEnvironment..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
rbEnvironment: aRBBrowserEnvironment | ||
rbEnvironment := aRBBrowserEnvironment |
2 changes: 1 addition & 1 deletion
2
repository/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/stream..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
formatting | ||
accessing | ||
stream: aStream | ||
stream := aStream |
2 changes: 1 addition & 1 deletion
2
repository/Seaside-Pharo-Gettext-Core.package/WAGetTextExporter.class/instance/stream.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
formatting | ||
accessing | ||
stream | ||
^ stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 6 additions & 37 deletions
43
...o-Gettext-Core.package/WATranslatedArgumentsFinder.class/instance/translatedArguments..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,8 @@ | ||
accessing | ||
translatedArguments: classesToSelect | ||
"self new translatedArguments" | ||
| searcher currentClass result innerMatchHandler extractFirstArgument extractReceiver classesToSearch | | ||
currentClass := WAValueHolder with: nil. | ||
result := GROrderedMultiMap new. | ||
innerMatchHandler := [ :node :literal | | ||
| key | | ||
key := (currentClass contents compiledMethodAt: node methodNode selector) asFullRingDefinition. | ||
result at: key add: literal value ]. | ||
extractFirstArgument := [ :node :answer | | ||
| firstArgument | | ||
firstArgument := node arguments first. | ||
firstArgument isLiteralNode ifTrue: [ | ||
innerMatchHandler value: node value: firstArgument ] ]. | ||
extractReceiver := [ :node :answer | | ||
node receiver isLiteralNode ifTrue: [ | ||
innerMatchHandler value: node value: node receiver ] ]. | ||
searcher := RBParseTreeSearcher new | ||
matches: '`@object translate: `#string' do: extractFirstArgument; | ||
matches: '`@object translate: `#string to: `@arg' do: extractFirstArgument; | ||
matches: '`#string seasideTranslated' do: extractReceiver; | ||
matches: '`#string seasideLazyTranslated' do: extractReceiver; | ||
matches: '`#string seasideTranslatedTo: `@arg' do: extractReceiver; | ||
yourself. | ||
"Note: for the reimplementation, you can most likely, probably, filter here, see the RBBrowserEnvironment class comment" | ||
classesToSearch := (classesToSelect = nil | ||
ifTrue: [ (RBBrowserEnvironment new allNonMetaClasses, RBBrowserEnvironment new allMetaClasses) ] | ||
ifFalse: [ (RBBrowserEnvironment new forClasses: classesToSelect) classes ]). | ||
classesToSearch do:[:class | | ||
class selectors do:[:selector | | ||
(searcher canMatchMethod: class >> selector) ifTrue: [ | ||
| tree | | ||
(tree := class parseTreeFor: selector) notNil ifTrue: [ | ||
currentClass contents: class. | ||
searcher executeTree: tree ] ] ] ]. | ||
^ Array streamContents: [ :stream | | ||
result keysDo: [ :key | | ||
stream nextPut: key -> (result allAt: key) ] ] | ||
|
||
| env | | ||
env := classesToSelect | ||
ifNil: [ RBBrowserEnvironment new forClasses: RBBrowserEnvironment new allNonMetaClasses, RBBrowserEnvironment new allMetaClasses ] | ||
ifNotNil: [ RBBrowserEnvironment new forClasses: classesToSelect ]. | ||
^ self translatedArgumentsIn: env |
34 changes: 34 additions & 0 deletions
34
...Gettext-Core.package/WATranslatedArgumentsFinder.class/instance/translatedArgumentsIn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
accessing | ||
translatedArgumentsIn: aRBBrowserEnvironment | ||
|
||
| searcher currentClass result innerMatchHandler extractFirstArgument extractReceiver | | ||
currentClass := WAValueHolder with: nil. | ||
result := GROrderedMultiMap new. | ||
innerMatchHandler := [ :node :literal | | ||
| key | | ||
key := (currentClass contents compiledMethodAt: node methodNode selector) asFullRingDefinition. | ||
result at: key add: literal value ]. | ||
extractFirstArgument := [ :node :answer | | ||
| firstArgument | | ||
firstArgument := node arguments first. | ||
firstArgument isLiteralNode ifTrue: [ | ||
innerMatchHandler value: node value: firstArgument ] ]. | ||
extractReceiver := [ :node :answer | | ||
node receiver isLiteralNode ifTrue: [ | ||
innerMatchHandler value: node value: node receiver ] ]. | ||
searcher := RBParseTreeSearcher new | ||
matches: '`@object translate: `#string' do: extractFirstArgument; | ||
matches: '`@object translate: `#string to: `@arg' do: extractFirstArgument; | ||
matches: '`#string seasideTranslated' do: extractReceiver; | ||
matches: '`#string seasideLazyTranslated' do: extractReceiver; | ||
matches: '`#string seasideTranslatedTo: `@arg' do: extractReceiver; | ||
yourself. | ||
aRBBrowserEnvironment methodsDo:[ :method | | ||
(searcher canMatchMethod:method) ifTrue: [ | ||
| tree | | ||
(tree := method parseTree) notNil ifTrue: [ | ||
currentClass contents: method methodClass. | ||
searcher executeTree: tree ] ] ]. | ||
^ Array streamContents: [ :stream | | ||
result keysDo: [ :key | | ||
stream nextPut: key -> (result allAt: key) ] ] |
22 changes: 19 additions & 3 deletions
22
...Tests-Pharo-Gettext.package/WAGetTextExporterTest.class/instance/fileContentsOfPOTFile.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...easide-Tests-Pharo-Gettext.package/WAGetTextExporterTest.class/instance/sortedTriplets.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
tests - test data | ||
sortedTriplets | ||
|
||
^ #(#('Seaside-Gettext-Examples,WAGettextExample>>#renderContentOn:,fontsize' 'Seaside-Gettext-Examples,WAGettextExample>>renderContentOn:,WAGettextExample>>renderContentOn:,WAGettextExample>>renderContentOn:,WAGettextExample>>renderContentOn:' 'fontsize') | ||
#('Seaside-Gettext-Examples,WAGettextExample>>#renderLocaleSelectionOn:,Select a locale below' 'Seaside-Gettext-Examples,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:' 'Select a locale below') | ||
#('Seaside-Gettext-Examples,WAGettextExample>>#renderLocaleSelectionOn:,locale' 'Seaside-Gettext-Examples,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:' 'locale')) | ||
^ #( | ||
#('WAGettextExample>>#renderContentOn:,fontsize' 'WAGettextExample>>renderContentOn:' 'fontsize') #('WAGettextExample>>#renderLocaleSelectionOn:,Select a locale below' 'WAGettextExample>>renderLocaleSelectionOn:' 'Select a locale below') #('WAGettextExample>>#renderLocaleSelectionOn:,locale' 'WAGettextExample>>renderLocaleSelectionOn:' 'locale')) |
6 changes: 3 additions & 3 deletions
6
...-Tests-Pharo-Gettext.package/WAGetTextExporterTest.class/instance/sortedTripletsString.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
tests - test data | ||
sortedTripletsString | ||
|
||
^ '#: Seaside-Gettext-Examples,WAGettextExample>>renderContentOn:,WAGettextExample>>renderContentOn:,WAGettextExample>>renderContentOn:,WAGettextExample>>renderContentOn:', String lf, | ||
^ '#: WAGettextExample>>renderContentOn:', String lf, | ||
'msgid "fontsize"', String lf, | ||
'msgstr ""', String lf, String cr, | ||
'#: Seaside-Gettext-Examples,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:', String lf, | ||
'#: WAGettextExample>>renderLocaleSelectionOn:', String lf, | ||
'msgid "Select a locale below"', String lf, | ||
'msgstr ""', String lf, String cr, | ||
'#: Seaside-Gettext-Examples,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:,WAGettextExample>>renderLocaleSelectionOn:', String lf, | ||
'#: WAGettextExample>>renderLocaleSelectionOn:', String lf, | ||
'msgid "locale"', String lf, | ||
'msgstr ""', String lf, String cr. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 5 additions & 28 deletions
33
....package/WAGetTextExporterTest.class/instance/translationLiteralsArrayAsCompiledMethod.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,7 @@ | ||
tests - test data | ||
translationLiteralsArrayAsCompiledMethod | ||
^ { | ||
'Select a locale below'->(OrderedCollection newFrom: { | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
}). | ||
'fontsize'->(OrderedCollection newFrom: { | ||
(WAGettextExample>>#renderContentOn:). | ||
(WAGettextExample>>#renderContentOn:). | ||
(WAGettextExample>>#renderContentOn:). | ||
(WAGettextExample>>#renderContentOn:). | ||
}). | ||
'locale'->(OrderedCollection newFrom: { | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
(WAGettextExample>>#renderLocaleSelectionOn:). | ||
}) | ||
}. | ||
|
||
^ { | ||
('Select a locale below' -> (Set newFrom: { (WAGettextExample >> #renderLocaleSelectionOn:) })). | ||
('fontsize' -> (Set newFrom: { (WAGettextExample >> #renderContentOn:) })). | ||
('locale' -> (Set newFrom: { (WAGettextExample >> #renderLocaleSelectionOn:) })) } |