"" | me | ctx _ thisContext. [ctx == nil or:[ctx receiver isKindOf: FileStream]] whileFalse:[ctx _ ctx sender]. ctx ifNotNil:[me _ ctx receiver]. me ifNotNil: [me converter: UTF8TextConverter new.]! SystemWindow subclass: #LanguageEditor instanceVariableNames: 'translator selectedTranslation selectedUntranslated translationsList untranslatedList translationText translationsFilter untranslatedFilter' classVariableNames: 'CheckMethods' poolDictionaries: '' category: 'Multilingual-Editor'! !LanguageEditor commentStamp: 'dgd 11/16/2003 15:02' prior: 0! Editor for Babel's languages. Open it from World Menu >> open... >> Language Editor (to open on default language) World Menu >> open... >> Language Editor for... (to choose the language) Or click: LanguageEditor openOnDefault. LanguageEditor open. See http://swiki.agro.uba.ar/small_land/191 for documentation ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 7/21/2004 16:55'! applyTranslations "private - try to apply the translations as much as possible all over the image" Project current updateLocaleDependents! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 7/21/2004 19:20'! browseMethodsWithTranslation | translation | self selectedTranslation isZero ifTrue: ["" self beep. self inform: 'select the translation to look for' translated. ^ self]. "" translation := self translations at: self selectedTranslation. self systemNavigation browseMethodsWithString: translation matchCase:false! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'yo 7/13/2004 10:19'! browseMethodsWithUntranslated | untranslated | self selectedUntranslated isZero ifTrue: ["" self beep. self inform: 'select the untranslated phrase to look for' translated. ^ self]. "" untranslated := self untranslated at: self selectedUntranslated. SystemNavigation default browseMethodsWithLiteral: untranslated. ! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/21/2003 12:14'! filterTranslations | filter | filter := FillInTheBlank request: 'filter with (empty string means no-filtering)' translated initialAnswer: self translationsFilter. "" self filterTranslations: filter! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/21/2003 12:12'! filterTranslations: aString | filter | filter := aString ifNil:['']. "" translationsFilter _ filter. self update: #translations. ! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/21/2003 12:20'! filterUntranslated | filter | filter := FillInTheBlank request: 'filter with (empty string means no-filtering)' translated initialAnswer: self untranslatedFilter. "" self filterUntranslated: filter! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/21/2003 12:20'! filterUntranslated: aString | filter | filter := aString ifNil: ['']. "" untranslatedFilter := filter. self update: #untranslated! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'gm 11/23/2003 23:09'! getTextExport GetTextExporter new export: self model! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 09:56'! loadFromFile | fileName | fileName := self selectTranslationFileName. fileName isNil ifTrue: ["" self beep. ^ self]. "" Cursor wait showWhile: [ self translator loadFromFileNamed: fileName. self changed: #translations. self changed: #untranslated]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 09:56'! mergeFromFile | fileName | fileName := self selectTranslationFileName. fileName isNil ifTrue: ["" self beep. ^ self]. "" Cursor wait showWhile: [ self translator loadFromFileNamed: fileName. self changed: #translations. self changed: #untranslated]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 09:59'! phrase: phraseString translation: translationString "set the models's translation for phraseString" self translator phrase: phraseString translation: translationString. self changed: #translations. self changed: #untranslated.! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/24/2003 21:53'! phraseToTranslate "answer a phrase to translate. use the selected untranslated phrase or ask for a new one" ^ self selectedUntranslated isZero ifTrue: [FillInTheBlank multiLineRequest: 'new phrase to translate' translated centerAt: Sensor cursorPoint initialAnswer: '' answerHeight: 200] ifFalse: [self untranslated at: self selectedUntranslated]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 09:59'! removeTranslation "remove the selected translation" | translation | self selectedTranslation isZero ifTrue: ["" self beep. self inform: 'select the translation to remove' translated. ^ self]. "" translation := self translations at: self selectedTranslation. "" (self confirm: ('Removing "{1}". Are you sure you want to do this?' translated format: {translation})) ifFalse: [^ self]. "" self translator removeTranslationFor: translation! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 09:59'! removeUntranslated "remove the selected untranslated phrase" | untranslated | self selectedUntranslated isZero ifTrue: ["" self beep. self inform: 'select the untranslated phrase to remove' translated. ^ self]. "" untranslated := self untranslated at: self selectedUntranslated. "" (self confirm: ('Removing "{1}". Are you sure you want to do this?' translated format: {untranslated})) ifFalse: [^ self]. "" self translator removeUntranslated: untranslated! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 7/21/2004 19:27'! report self reportString openInWorkspaceWithTitle: 'report' translated! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 10:01'! saveToFile "save the translator to a file" | fileName | fileName := FillInTheBlank request: 'file name' translated initialAnswer: self model localeID isoString , '.translation'. (fileName isNil or: [fileName isEmpty]) ifTrue: ["" self beep. ^ self]. "" Cursor wait showWhile: [ self translator saveToFileNamed: fileName]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/24/2003 22:40'! searchTranslation | search | search := FillInTheBlank request: 'search for' translated initialAnswer: ''. (search isNil or: [search isEmpty]) ifTrue: ["" self beep. ^ self]. "" self searchTranslation: search! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 10:00'! searchTranslation: aString | translations results index | translations := self translations. results := translations select: [:each | "" ('*' , aString , '*' match: each) or: ['*' , aString , '*' match: (self translator translationFor: each)]]. "" results isEmpty ifTrue: ["" self inform: 'no matches for' translated , ' ''' , aString , ''''. ^ self]. "" results size = 1 ifTrue: ["" self selectTranslationPhrase: results first. ^ self]. "" index := (PopUpMenu labelArray: (results collect: [:each | "" (each copy replaceAll: Character cr with: $\) , ' -> ' , ((self translator translationFor: each) copy replaceAll: Character cr with: $\)])) startUpWithCaption: 'select the translation...' translated. "" index isZero ifTrue: ["" self beep. ^ self]. "" self selectTranslationPhrase: (results at: index)! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/27/2003 20:42'! searchUntranslated | search | search := FillInTheBlank request: 'search for' translated initialAnswer: ''. (search isNil or: [search isEmpty]) ifTrue: ["" self beep. ^ self]. "" self searchUntranslated: search! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/1/2003 14:28'! searchUntranslated: aString | untranslateds results index | untranslateds := self untranslated. results := untranslateds select: [:each | '*' , aString , '*' match: each]. "" results isEmpty ifTrue: ["" self inform: 'no matches for' translated , ' ''' , aString , ''''. ^ self]. "" results size = 1 ifTrue: ["" self selectUntranslatedPhrase: results first. ^ self]. "" index := (PopUpMenu labelArray: (results collect: [:each | each copy replaceAll: Character cr with: $\])) startUpWithCaption: 'select the untranslated phrase...' translated. "" index isZero ifTrue: ["" self beep. ^ self]. "" self selectUntranslatedPhrase: (results at: index)! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/24/2003 22:15'! selectTranslationFileName "answer a file with a translation" | file | file := (StandardFileMenu oldFileMenu: FileDirectory default withPattern: '*.translation') startUpWithCaption: 'Select the file...' translated. ^ file isNil ifFalse: [file directory fullNameFor: file name]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/24/2003 22:49'! selectTranslationPhrase: phraseString self selectedTranslation: (self translations indexOf: phraseString)! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/27/2003 20:43'! selectUntranslatedPhrase: phraseString self selectedUntranslated: (self untranslated indexOf: phraseString)! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'mir 8/11/2004 10:00'! status "answer a status string" | translationsSize untranslatedSize | translationsSize := self translator translations size. untranslatedSize := self translator untranslated size. ^ '· {1} phrases · {2} translated · {3} untranslated ·' translated format: {translationsSize + untranslatedSize. translationsSize. untranslatedSize}! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/24/2003 21:53'! translate "translate a phrase" | phrase | phrase := self phraseToTranslate. "" (phrase isNil or: [phrase = '']) ifTrue: ["" self beep. ^ self]. "" self translatePhrase: phrase! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 8/24/2003 21:55'! translatePhrase: aString "translate aString" | translation | translation := FillInTheBlank multiLineRequest: 'translation for: ' translated , '''' , aString , '''' centerAt: Sensor cursorPoint initialAnswer: aString answerHeight: 200. "" (translation isNil or: [translation = '']) ifTrue: ["" self beep. ^ self]. "" self phrase: aString translation: translation! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/21/2003 12:09'! translationsFilterWording ^ (self translationsFilter isEmpty ifTrue: ['filter' translated] ifFalse: ['filtering: {1}' translated format:{self translationsFilter}]) ! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'gm 8/30/2003 02:00'! translationsKeystroke: aChar "Respond to a Command key in the translations list." aChar == $x ifTrue: [^ self removeTranslation]. aChar == $E ifTrue: [^ self browseMethodsWithTranslation]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'gm 8/30/2003 01:56'! translationsMenu: aMenu ^ aMenu add: 'remove (x)' translated action: #removeTranslation; add: 'where (E)' translated action: #browseMethodsWithTranslation; yourself! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 9/21/2003 12:19'! untranslatedFilterWording ^ self untranslatedFilter isEmpty ifTrue: ['filter' translated] ifFalse: ['filtering: {1}' translated format: {self untranslatedFilter}]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'gm 8/30/2003 02:01'! untranslatedKeystroke: aChar "Respond to a Command key in the translations list." aChar == $t ifTrue: [^ self translate]. aChar == $E ifTrue: [^ self browseMethodsWithUntranslated]! ! !LanguageEditor methodsFor: 'gui methods' stamp: 'dgd 10/13/2003 18:30'! untranslatedMenu: aMenu ^ aMenu add: 'remove' translated action: #removeUntranslated; add: 'translate (t)' translated action: #translate; add: 'where (E)' translated action: #browseMethodsWithUntranslated; yourself! ! !LanguageEditor methodsFor: 'initialization - statusbar' stamp: 'dgd 9/21/2003 11:38'! createStatusbar "create the statusbar for the receiver" | statusbar | statusbar := self createRow. "" statusbar addMorph: ((UpdatingStringMorph on: self selector: #status) growable: true; useStringFormat; hResizing: #spaceFill). "" ^ statusbar! ! !LanguageEditor methodsFor: 'initialization - statusbar' stamp: 'dgd 9/21/2003 11:39'! initializeStatusbar "initialize the receiver's statusbar" self addMorph: self createStatusbar frame: (0 @ 0.93 corner: 1 @ 1)! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'dgd 8/24/2003 22:41'! createButtonLabel: aString action: actionSelector help: helpString "create a toolbar for the receiver" | button | button := SimpleButtonMorph new target: self; label: aString translated "font: Preferences standardButtonFont"; actionSelector: actionSelector; setBalloonText: helpString translated; color: self model defaultBackgroundColor twiceDarker; borderWidth: 2; borderColor: #raised. "" ^ button! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'mir 7/21/2004 18:01'! createMainToolbar "create a toolbar for the receiver" | toolbar | toolbar := self createRow. "" " toolbar addMorphBack: (self createUpdatingButtonWording: #debugWording action: #switchDebug help: 'Switch the debug flag')." toolbar addTransparentSpacerOfSize: 5 @ 0. "" toolbar addMorphBack: (self createButtonLabel: 'save' action: #saveToFile help: 'Save the translations to a file'). toolbar addMorphBack: (self createButtonLabel: 'load' action: #loadFromFile help: 'Load the translations from a file'). toolbar addMorphBack: (self createButtonLabel: 'merge' action: #mergeFromFile help: 'Merge the current translations with the translations in a file'). "" toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'apply' action: #applyTranslations help: 'Apply the translations as much as possible.'). "" toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'check translations' action: #check help: 'Check the translations and report the results.'). toolbar addMorphBack: (self createButtonLabel: 'report' action: #report help: 'Create a report.'). toolbar addMorphBack: (self createButtonLabel: 'gettext export' action: #getTextExport help: 'Exports the translations in GetText format.'). "" ^ toolbar! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'dgd 9/21/2003 11:46'! createRow "create a row" | row | row := AlignmentMorph newRow. row layoutInset: 3; wrapCentering: #center; cellPositioning: #leftCenter. "" ^ row! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'dgd 9/21/2003 12:08'! createTranslationsToolbar "create a toolbar for the receiver" | toolbar | toolbar := self createRow. "" toolbar addMorphBack: (self createUpdatingButtonWording: #translationsFilterWording action: #filterTranslations help: 'Filter the translations list.'). toolbar addTransparentSpacerOfSize: 5 @ 0. "" toolbar addMorphBack: (self createButtonLabel: 'search' action: #searchTranslation help: 'Search for a translation containing...'). toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'remove' action: #removeTranslation help: 'Remove the selected translation. If none is selected, ask for the one to remove.'). "" toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'where' action: #browseMethodsWithTranslation help: 'Launch a browser on all methods that contain the phrase as a substring of any literal String.'). "" ^ toolbar! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'dgd 9/21/2003 12:18'! createUntranslatedToolbar "create a toolbar for the receiver" | toolbar | toolbar := self createRow. ""toolbar addMorphBack: (self createUpdatingButtonWording: #untranslatedFilterWording action: #filterUntranslated help: 'Filter the untranslated list.'). toolbar addTransparentSpacerOfSize: 5 @ 0. "" toolbar addMorphBack: (self createButtonLabel: 'search' action: #searchUntranslated help: 'Search for a untranslated phrase containing...'). toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'remove' action: #removeUntranslated help: 'Remove the selected untranslated phrease. If none is selected, ask for the one to remove.'). "" toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'translate' action: #translate help: 'Translate the selected untranslated phrase or a new phrase'). "" toolbar addTransparentSpacerOfSize: 5 @ 0. toolbar addMorphBack: (self createButtonLabel: 'where' action: #browseMethodsWithUntranslated help: 'Launch a browser on all methods that contain the phrase as a substring of any literal String.'). "" ^ toolbar! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'dgd 8/27/2003 17:33'! createUpdatingButtonWording: wordingSelector action: actionSelector help: helpString "create a toolbar for the receiver" | button | button := (UpdatingSimpleButtonMorph newWithLabel: '-') target: self; wordingSelector: wordingSelector; actionSelector: actionSelector; setBalloonText: helpString translated; color: self model defaultBackgroundColor twiceDarker; borderWidth: 1; borderColor: #raised; cornerStyle: #square. "" ^ button! ! !LanguageEditor methodsFor: 'initialization - toolbar' stamp: 'dgd 9/21/2003 11:27'! initializeToolbars "initialize the receiver's toolbar" self addMorph: self createMainToolbar frame: (0 @ 0 corner: 1 @ 0.09). "" self addMorph: self createTranslationsToolbar frame: (0 @ 0.09 corner: 0.5 @ 0.18). self addMorph: self createUntranslatedToolbar frame: (0.5 @ 0.09 corner: 1 @ 0.18)! ! !LanguageEditor methodsFor: 'updating' stamp: 'dgd 8/28/2003 10:31'! okToChange "Allows a controller to ask this of any model" self selectedTranslation isZero ifTrue: [^ true]. "" translationText hasUnacceptedEdits ifFalse: [^ true]. ^ (CustomMenu confirm: 'Discard the changes to currently selected translated phrase?' translated) and: ["" translationText hasUnacceptedEdits: false. true]! ! !LanguageEditor methodsFor: 'updating' stamp: 'dgd 8/27/2003 19:59'! refreshTranslations "refresh the translations panel" self changed: #translations. self selectedTranslation: 0! ! !LanguageEditor methodsFor: 'updating' stamp: 'dgd 8/27/2003 19:59'! refreshUntranslated "refresh the untranslated panel" self changed: #untranslated. self selectedUntranslated: 0! ! !LanguageEditor methodsFor: 'updating' stamp: 'dgd 8/25/2003 20:11'! update: aSymbol "Receive a change notice from an object of whom the receiver is a dependent." super update: aSymbol. "" aSymbol == #untranslated ifTrue: [self refreshUntranslated]. aSymbol == #translations ifTrue: [self refreshTranslations]! ! !LanguageEditor methodsFor: 'initialization' stamp: 'mir 8/11/2004 09:59'! initializeOn: aLanguage "initialize the receiver on aLanguage" "" selectedTranslation := 0. selectedUntranslated := 0. "" translator := aLanguage. "" self setLabel: 'Language editor for: ' translated , self translator name. "" self initializeToolbars. self initializePanels. self initializeStatusbar! ! !LanguageEditor methodsFor: 'initialization' stamp: 'dgd 9/21/2003 11:40'! initializePanels "initialize the receiver's panels" translationsList := PluggableListMorph on: self list: #translations selected: #selectedTranslation changeSelected: #selectedTranslation: menu: #translationsMenu: keystroke: #translationsKeystroke:. translationsList setBalloonText: 'List of all the translated phrases.' translated. "" untranslatedList := PluggableListMorph on: self list: #untranslated selected: #selectedUntranslated changeSelected: #selectedUntranslated: menu: #untranslatedMenu: keystroke: #untranslatedKeystroke:. untranslatedList setBalloonText: 'List of all the untranslated phrases.' translated. "" translationText := PluggableTextMorph on: self text: #translation accept: #translation: readSelection: nil menu: nil. translationText setBalloonText: 'Translation for the selected phrase in the upper list.' translated. "" self addMorph: translationsList frame: (0 @ 0.18 corner: 0.5 @ 0.66). self addMorph: untranslatedList frame: (0.5 @ 0.18 corner: 1 @ 0.93). self addMorph: translationText frame: (0 @ 0.66 corner: 0.5 @ 0.93)! ! !LanguageEditor methodsFor: 'accessing' stamp: 'dgd 8/24/2003 19:13'! selectedTranslation "answer the selectedTranslation" ^ selectedTranslation! ! !LanguageEditor methodsFor: 'accessing' stamp: 'dgd 8/24/2003 21:56'! selectedTranslation: anInteger "change the receiver's selectedTranslation" selectedTranslation := anInteger. "" self changed: #selectedTranslation. self changed: #translation! ! !LanguageEditor methodsFor: 'accessing' stamp: 'dgd 8/24/2003 21:57'! selectedUntranslated "answer the selectedUntranslated" ^ selectedUntranslated! ! !LanguageEditor methodsFor: 'accessing' stamp: 'dgd 8/24/2003 21:57'! selectedUntranslated: anInteger "change the selectedUntranslated" selectedUntranslated := anInteger. "" self changed: #selectedUntranslated! ! !LanguageEditor methodsFor: 'accessing' stamp: 'mir 8/11/2004 10:00'! translation "answer the translation for the selected phrase" self selectedTranslation isZero ifTrue: [^ '