#FEATURE by cg draft
authorClaus Gittinger <cg@exept.de>
Fri, 12 Oct 2018 12:46:23 +0200
changeset 3601 9afa4a73568a
parent 3600 872b1d9a74f8
child 3602 ca4228ee4d3c
#FEATURE by cg class: Tools::InternationalLanguageTranslationEditor added: #editedLanguage: comment/format in:21 methods changed: #languagesList #objectsList category of: #postBuildSearchBoxView: #postBuildSearchTextView: #postBuildTranslationsPanel: #postBuildWith:
Tools__InternationalLanguageTranslationEditor.st
--- a/Tools__InternationalLanguageTranslationEditor.st	Fri Oct 12 12:45:59 2018 +0200
+++ b/Tools__InternationalLanguageTranslationEditor.st	Fri Oct 12 12:46:23 2018 +0200
@@ -1108,7 +1108,7 @@
 
 objectsList
 
-    ^ keyStringsToLanguageMappings
+    ^ self keyStringsToLanguageMappings
 !
 
 selectListIndex: rowIndex
@@ -1123,8 +1123,9 @@
 !
 
 selectedKey
-   "Returns the current selected key if there is one row seleted. Otherwise, returns nil"
-     |rowSelectionIndex |
+    "Returns the current selected key if there is one row seleted. Otherwise, returns nil"
+
+    | rowSelectionIndex |
 
     keyStringsToLanguageMappings isNil ifTrue:[^nil].
     self selectedKeyRow value isNil ifTrue:[^nil].
@@ -1144,6 +1145,7 @@
 
 searchForSimilarTranslation
     "Looks for a quite similar translation for the key and display a dialog with available options"
+
     |similarTranslationsAssociations selectedTranslation key|
 
     self shouldSearchForSimilarTranslation ifFalse:[^self].
@@ -1154,17 +1156,17 @@
     similarTranslationsAssociations isEmpty ifTrue:[^self].
 
     similarTranslationsAssociations := similarTranslationsAssociations associations inject: OrderedCollection new into:[:collection :association |
-	collection detect:[:selectedAssociation |
-	    selectedAssociation value sameAs: association value] ifNone:[collection add: association].
-	collection].
+        collection detect:[:selectedAssociation |
+            selectedAssociation value sameAs: association value] ifNone:[collection add: association].
+        collection].
     selectedTranslation := Dialog
-	choose:'Choose one if you consider it´s usefull to translate:
+        choose:'Choose one if you consider it´s usefull to translate:
     ',
-	'<', key, '>  ', (self currentExampleLanguageText ifNil:[''])
-	fromList: (similarTranslationsAssociations collect:[:each |  '<', each key, '>  ', each value])
-	values: (similarTranslationsAssociations collect:[:each | each value])
-	lines:10
-	cancel: nil.
+        '<', key, '>  ', (self currentExampleLanguageText ifNil:[''])
+        fromList: (similarTranslationsAssociations collect:[:each |  '<', each key, '>  ', each value])
+        values: (similarTranslationsAssociations collect:[:each | each value])
+        lines:10
+        cancel: nil.
 
     selectedTranslation notNil ifTrue:[self languageTextHolderValue: selectedTranslation].
 ! !
@@ -1277,7 +1279,7 @@
 
 languagesList
     languagesList isNil ifTrue:[
-	languagesList := List withAll:(self keyStringAndLanguageSelectionTable languages).
+        languagesList := List withAll:(keyStringsToLanguageMappings languages).
     ].
     ^ languagesList.
 !
@@ -1452,10 +1454,8 @@
 
 updateKeyStringsToLanguageMappings
 
-      keyStringsToLanguageMappings
-	at:lastSelectedKey
-	language:lastLanguage
-	put: self newLanguageText.
+    keyStringsToLanguageMappings
+        at:lastSelectedKey language:lastLanguage put: self newLanguageText.
 !
 
 updateLanguageAndKeySelection
@@ -1524,12 +1524,16 @@
 !
 
 requestEncoderStringFor: lang
-  "Returns an encoder string and updates the language's info"
+    "Returns an encoder string and updates the language's info"
+  
     |encoderString encoder|
+
     encoderString := self requestEncoderDialog.
     encoderString notEmpty ifTrue:[
-	encoder := CharacterEncoder encoderFor: encoderString ifAbsent:nil.
-	encoder notNil ifTrue:[keyStringsToLanguageMappings atLanguage: lang putEncoder: encoder.].
+        encoder := CharacterEncoder encoderFor: encoderString ifAbsent:nil.
+        encoder notNil ifTrue:[
+            keyStringsToLanguageMappings atLanguage: lang putEncoder: encoder.
+        ].
     ].
     ^encoderString
 !
@@ -1645,10 +1649,18 @@
     super closeRequest
 !
 
+editedLanguage:aSingleLanguageKey
+    self languagesList contents:{ aSingleLanguageKey }.
+    self shownLanguages contents:{ aSingleLanguageKey }.
+!
+
 initialize
     modified := false.
     inSingleFileMode := false.
     methodsUsingKey := Dictionary new.
+    keyStringsToLanguageMappings := KeyStringsToLanguageMappings new.
+    languagesList := List withAll:(keyStringsToLanguageMappings languages).
+    
     super initialize
 !
 
@@ -1661,9 +1673,7 @@
 postBuildDataSet:aView
     dataSetView := aView.
     aView selectedColIndexHolder onChangeSend:#selectionChanged to:self.
-! !
-
-!InternationalLanguageTranslationEditor methodsFor:'initialize'!
+!
 
 postBuildSearchBoxView: aBoxView
 
@@ -1717,7 +1727,7 @@
 
     key := Dialog request:'New Key:'.
     key isEmpty ifTrue:[^self].
-    
+
     (self includesKey:key) ifFalse:[
         keyStringsToLanguageMappings addKey:key.
         modified := true.
@@ -1834,17 +1844,17 @@
 
 generateMissingTranslations: keys for: languages using: translator
     keys do:[:string |
-	languages do:[:lang |
-	    | translation |
-
-	    translation := keyStringsToLanguageMappings at:string language:lang.
-	    translation isNil ifTrue:[
-		translation := translator value: lang value: string.
-		translation notNil ifTrue:[
-		    keyStringsToLanguageMappings at: string language: lang put: translation.
-		].
-	    ].
-	].
+        languages do:[:lang |
+            | translation |
+
+            translation := keyStringsToLanguageMappings at:string language:lang.
+            translation isNil ifTrue:[
+                translation := translator value: lang value: string.
+                translation notNil ifTrue:[
+                    keyStringsToLanguageMappings at: string language: lang put: translation.
+                ].
+            ].
+        ].
     ].
 
     "Created: / 19-02-2015 / 12:31:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1852,9 +1862,9 @@
 
 generateMissingTranslationsFor: languages
     self
-	generateMissingTranslations: keyStringsToLanguageMappings keys
-				for: languages
-			      using: [ :lang :string | '**%1** %2' bindWith: lang asUppercase with: string ]
+        generateMissingTranslations: keyStringsToLanguageMappings keys
+        for: languages
+        using: [ :lang :string | '**%1** %2' bindWith: lang asUppercase with: string ]
 
     "Created: / 19-02-2015 / 12:39:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
@@ -1898,18 +1908,18 @@
     missingStrings asSet inspect
 !
 
-menuNew
+menuNew    
     modified ifTrue:[
-	(Dialog
-	    confirm:(resources stringWithCRs:'Modified translations have not been changed.\\Create new translations set anyway ?')
-	    default:false) ifFalse:[^ self].
+        (Dialog
+            confirm:(resources stringWithCRs:'Modified translations have not been changed.\\Create new translations set anyway ?')
+            default:false) ifFalse:[^ self].
     ].
 
     keyStringsToLanguageMappings initialize.
     keyStringsToLanguageMappings changed.
 
-    self languagesList contents:self keyStringAndLanguageSelectionTable languages.
-    self shownLanguages contents:self keyStringAndLanguageSelectionTable languages.
+    self languagesList contents:keyStringsToLanguageMappings languages.
+    self shownLanguages contents:keyStringsToLanguageMappings languages.
     modified := false.
 !
 
@@ -1943,7 +1953,7 @@
 !
 
 menuSaveAll
-"Saves all the languages in the fileName from where the language resource was obtained."
+    "Saves all the languages in the fileName from where the language resource was obtained."
     keyStringsToLanguageMappings languagesInUse do:[:each | self saveLanguage: each].
 !
 
@@ -2069,11 +2079,14 @@
 removeLanguage
     |languagesToRemove|
 
-    languagesToRemove := Dialog chooseMultiple:'Which language(s) do you want to remove?' fromList:languagesList lines:10.
+    languagesToRemove := Dialog 
+                            chooseMultiple:'Which language(s) do you want to remove?' 
+                            fromList:languagesList lines:10.
+
     languagesToRemove isEmptyOrNil ifTrue:[^ self ].
     (Dialog confirm: 'Are you sure to remove the languages: ', languagesToRemove printString) ifTrue:[
-	  self languagesList removeAll:languagesToRemove.
-	  self shownLanguages removeAll:languagesToRemove.
+          self languagesList removeAll:languagesToRemove.
+          self shownLanguages removeAll:languagesToRemove.
     ].
 !
 
@@ -2083,11 +2096,11 @@
     rowSelectionIndex := self selectedKeyRow value.
     rowSelectionIndex isNil ifTrue:[^self].
     rowSelectionIndex ~~ 0 ifTrue:[
-	selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex ifAbsent:nil.
-	selectedKey isNil ifTrue:[^self].
-	(Dialog confirm:(resources string:'Really remove key %1' with:selectedKey)) ifTrue:[
-	    keyStringsToLanguageMappings removeKey:selectedKey.
-	].
+        selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex ifAbsent:nil.
+        selectedKey isNil ifTrue:[^self].
+        (Dialog confirm:(resources string:'Really remove key %1' with:selectedKey)) ifTrue:[
+            keyStringsToLanguageMappings removeKey:selectedKey.
+        ].
     ].
 !
 
@@ -2248,12 +2261,12 @@
 
     menu := Menu new.
     keyStringsToLanguageMappings notNil ifTrue:[
-	keyStringsToLanguageMappings languages do:[:lang |
-	    menu addItem:
-		(MenuItem
-		    label: (resources string: 'Generate Missing Translations - %1' with: lang asUppercase)
-		    itemValue: [ self generateMissingTranslationsFor: (Array with: lang) ])
-	].
+        keyStringsToLanguageMappings languages do:[:lang |
+            menu addItem:
+                (MenuItem
+                    label: (resources string: 'Generate Missing Translations - %1' with: lang asUppercase)
+                    itemValue: [ self generateMissingTranslationsFor: (Array with: lang) ])
+        ].
     ].
     ^ menu
 
@@ -2300,41 +2313,41 @@
     "/ follow the common-xlations algrithm of ResourcePack
     "/ (which knows how to xlate strings with additional special chars.)
     newTranslationKeys :=
-	newTranslationKeys collect:[:oldKey |
-	    |newKey methods|
-
-	    (oldKey endsWith:' ...') ifTrue:[
-		newKey := oldKey copyButLast:4.
-	    ] ifFalse:[ (oldKey endsWith:'...') ifTrue:[
-		newKey := oldKey copyButLast:3.
-	    ] ifFalse:[ ('\.:?=,!! ' includes:oldKey last) ifTrue:[
-		newKey := oldKey copyButLast:1.
-	    ] ifFalse:[ ((oldKey first == $() and:[ oldKey last == $) ]) ifTrue:[
-		newKey := oldKey copyFrom:2 to:oldKey size - 1
-	    ] ifFalse:[ ((oldKey first == $[) and:[ oldKey last == $] ]) ifTrue:[
-		newKey := oldKey copyFrom:2 to:oldKey size - 1
-	    ] ifFalse:[
-		newKey :=oldKey
-	    ]]]]].
-	    "/ must attach oldKey-methods to newKey
-	    methods := methodsUsingKey at:oldKey ifAbsent:nil.
-	    methods notNil ifTrue:[
-		(methodsUsingKey at:newKey ifAbsentPut:[Set new]) addAll:methods
-	    ].
-	    newKey
-	].
+        newTranslationKeys collect:[:oldKey |
+            |newKey methods|
+
+            (oldKey endsWith:' ...') ifTrue:[
+                newKey := oldKey copyButLast:4.
+            ] ifFalse:[ (oldKey endsWith:'...') ifTrue:[
+                newKey := oldKey copyButLast:3.
+            ] ifFalse:[ ('\.:?=,!! ' includes:oldKey last) ifTrue:[
+                newKey := oldKey copyButLast:1.
+            ] ifFalse:[ ((oldKey first == $() and:[ oldKey last == $) ]) ifTrue:[
+                newKey := oldKey copyFrom:2 to:oldKey size - 1
+            ] ifFalse:[ ((oldKey first == $[) and:[ oldKey last == $] ]) ifTrue:[
+                newKey := oldKey copyFrom:2 to:oldKey size - 1
+            ] ifFalse:[
+                newKey :=oldKey
+            ]]]]].
+            "/ must attach oldKey-methods to newKey
+            methods := methodsUsingKey at:oldKey ifAbsent:nil.
+            methods notNil ifTrue:[
+                (methodsUsingKey at:newKey ifAbsentPut:[Set new]) addAll:methods
+            ].
+            newKey
+        ].
 
     newTranslationKeys := newTranslationKeys asSet.
     newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
 
     newTranslationKeys notEmpty ifTrue:[
-	stringKeys := newTranslationKeys select:[:k | k isString].
-	nonStringKeys := newTranslationKeys select:[:k | k isString not].
-
-	stringKeys := stringKeys asSortedCollection.
-	keyStringsToLanguageMappings addKeys:stringKeys.
-	keyStringsToLanguageMappings addKeys:nonStringKeys.
-	modified := true.
+        stringKeys := newTranslationKeys select:[:k | k isString].
+        nonStringKeys := newTranslationKeys select:[:k | k isString not].
+
+        stringKeys := stringKeys asSortedCollection.
+        keyStringsToLanguageMappings addKeys:stringKeys.
+        keyStringsToLanguageMappings addKeys:nonStringKeys.
+        modified := true.
     ].
 !
 
@@ -2649,8 +2662,8 @@
 !
 
 includesKey: aKey
-    keyStringsToLanguageMappings isNil ifTrue:[^false].
-    ^keyStringsToLanguageMappings includesKey:aKey
+    ^ keyStringsToLanguageMappings notNil
+    and:[ keyStringsToLanguageMappings includesKey:aKey ]
 !
 
 isSearchForSimilarTranslationEnabled