#FEATURE by cg draft
authorClaus Gittinger <cg@exept.de>
Fri, 12 Oct 2018 11:32:55 +0200
changeset 3599 5b4499069510
parent 3598 76dd8e2f2fd8
child 3600 872b1d9a74f8
#FEATURE by cg class: Tools::InternationalLanguageTranslationEditor added: #mergeLanguages comment/format in: #addTranslation category of: #searchForSimilarTranslation class: Tools::InternationalLanguageTranslationEditor class changed: #mainMenu
Tools__InternationalLanguageTranslationEditor.st
--- a/Tools__InternationalLanguageTranslationEditor.st	Thu Oct 11 13:28:10 2018 +0200
+++ b/Tools__InternationalLanguageTranslationEditor.st	Fri Oct 12 11:32:55 2018 +0200
@@ -660,169 +660,176 @@
 
     <resource: #menu>
 
-    ^
+    ^ 
      #(Menu
-	(
-	 (MenuItem
-	    label: 'File'
-	    submenu:
-	   (Menu
-	      (
-	       (MenuItem
-		  label: 'New'
-		  itemValue: menuNew
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'Open Resources for Package or Project...'
-		  itemValue: menuOpenByPackage
-		)
-	       (MenuItem
-		  label: 'Open Resource File...'
-		  itemValue: menuOpen
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'Save All Resource Files'
-		  itemValue: menuSaveAll
-		)
-	       (MenuItem
-		  label: 'Save Resource File'
-		  itemValue: menuSave
-		)
-	       (MenuItem
-		  label: 'Save Resource File As...'
-		  itemValue: menuSaveAs
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'Import existing translations from file...'
-		  itemValue: importExistingTranslationsFromFile
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'Set Current NameSpace'
-		  itemValue: changeLastNameSpace
-		)
-	       (MenuItem
-		  label: 'Set Current Package'
-		  itemValue: changeLastPackage
-		  isVisible: false
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'Exit'
-		  itemValue: closeRequest
-		)
-	       )
-	      nil
-	      nil
-	    )
-	  )
-	 (MenuItem
-	    label: 'View'
-	    submenu:
-	   (Menu
-	      (
-	       (MenuItem
-		  label: 'Show Missing Translations Only'
-		  indication: showMissingTranslationsOnly
-		)
-	       (MenuItem
-		  label: 'Show Search Box'
-		  indication: searchBoxVisible
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'Shown Languages'
-		  submenuChannel: shownLanguagesMenu
-		)
-	       )
-	      nil
-	      nil
-	    )
-	  )
-	 (MenuItem
-	    label: 'Languages'
-	    submenu:
-	   (Menu
-	      (
-	       (MenuItem
-		  label: 'Add Language...'
-		  itemValue: addLanguage
-		)
-	       (MenuItem
-		  label: 'Remove Language...'
-		  itemValue: removeLanguage
-		)
-	       )
-	      nil
-	      nil
-	    )
-	  )
-	 (MenuItem
-	    label: 'Translations'
-	    submenuChannel: translationsMenuSpec
-	  )
-	 (MenuItem
-	    label: 'Preferences'
-	    submenu:
-	   (Menu
-	      (
-	       (MenuItem
-		  label: 'Auto Accept Changes'
-		  indication: autoAcceptHolder
-		)
-	       (MenuItem
-		  label: 'Search For Similar Translations'
-		  indication: searchForSimilarTranslationEnableHolder
-		)
-	       (MenuItem
-		  label: 'Always Write UTF8'
-		  indication: alwaysWriteUTF8Holder
-		)
-	       )
-	      nil
-	      nil
-	    )
-	  )
-	 (MenuItem
-	    label: 'Help'
-	    startGroup: right
-	    submenu:
-	   (Menu
-	      (
-	       (MenuItem
-		  label: 'Documentation'
-		  itemValue: openDocumentation
-		)
-	       (MenuItem
-		  label: '-'
-		)
-	       (MenuItem
-		  label: 'About this Application...'
-		  itemValue: openAboutThisApplication
-		)
-	       )
-	      nil
-	      nil
-	    )
-	  )
-	 )
-	nil
-	nil
+        (
+         (MenuItem
+            label: 'File'
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'New'
+                  itemValue: menuNew
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Open Resources for Package or Project...'
+                  itemValue: menuOpenByPackage
+                )
+               (MenuItem
+                  label: 'Open Resource File...'
+                  itemValue: menuOpen
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Save All Resource Files'
+                  itemValue: menuSaveAll
+                )
+               (MenuItem
+                  label: 'Save Resource File'
+                  itemValue: menuSave
+                )
+               (MenuItem
+                  label: 'Save Resource File As...'
+                  itemValue: menuSaveAs
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Import existing translations from file...'
+                  itemValue: importExistingTranslationsFromFile
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Set Current NameSpace'
+                  itemValue: changeLastNameSpace
+                )
+               (MenuItem
+                  label: 'Set Current Package'
+                  itemValue: changeLastPackage
+                  isVisible: false
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Exit'
+                  itemValue: closeRequest
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'View'
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'Show Missing Translations Only'
+                  indication: showMissingTranslationsOnly
+                )
+               (MenuItem
+                  label: 'Show Search Box'
+                  indication: searchBoxVisible
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Shown Languages'
+                  submenuChannel: shownLanguagesMenu
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'Languages'
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'Add Language...'
+                  itemValue: addLanguage
+                )
+               (MenuItem
+                  label: 'Remove Language...'
+                  itemValue: removeLanguage
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Merge...'
+                  itemValue: mergeLanguages
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'Translations'
+            submenuChannel: translationsMenuSpec
+          )
+         (MenuItem
+            label: 'Preferences'
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'Auto Accept Changes'
+                  indication: autoAcceptHolder
+                )
+               (MenuItem
+                  label: 'Search For Similar Translations'
+                  indication: searchForSimilarTranslationEnableHolder
+                )
+               (MenuItem
+                  label: 'Always Write UTF8'
+                  indication: alwaysWriteUTF8Holder
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'Help'
+            startGroup: right
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'Documentation'
+                  itemValue: openDocumentation
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'About this Application...'
+                  itemValue: openAboutThisApplication
+                )
+               )
+              nil
+              nil
+            )
+          )
+         )
+        nil
+        nil
       )
 !
 
@@ -1133,7 +1140,7 @@
     "Created: / 15-06-2007 / 18:59:51 / Administrador"
 ! !
 
-!InternationalLanguageTranslationEditor methodsFor:'additionalFuncionalities'!
+!InternationalLanguageTranslationEditor methodsFor:'additionalFunctionalities'!
 
 searchForSimilarTranslation
     "Looks for a quite similar translation for the key and display a dialog with available options"
@@ -1710,9 +1717,10 @@
 
     key := Dialog request:'New Key:'.
     key isEmpty ifTrue:[^self].
+    
     (self includesKey:key) ifFalse:[
-	keyStringsToLanguageMappings addKey:key.
-	modified := true.
+        keyStringsToLanguageMappings addKey:key.
+        modified := true.
     ].
    index := keyStringsToLanguageMappings indexOfKey:key.
    self selectedKeyRow value:index
@@ -1950,6 +1958,41 @@
     self saveResourceFile:aFilename for:lang asSymbol
 !
 
+mergeLanguages
+    |sourceLanguage destLanguage possibleDestinationLanguages|
+
+    sourceLanguage := Dialog 
+                        request:'Merge entries from:' 
+                        initialAnswer:nil 
+                        list:(self languagesList)
+                        title:'Source language'.
+    sourceLanguage isEmptyOrNil ifTrue:[^ self].
+
+    possibleDestinationLanguages := self languagesList copyWithout:sourceLanguage.
+    
+    destLanguage := Dialog 
+                        request:'Destination language:\(Missing entries in destination are filled in from source)' withCRs 
+                        initialAnswer:(possibleDestinationLanguages size == 1
+                                        ifTrue:[possibleDestinationLanguages first]
+                                        ifFalse:[nil])
+                        list:possibleDestinationLanguages
+                        title:'Destination language'.
+    destLanguage isEmptyOrNil ifTrue:[^ self].
+
+    "/ all empty entries of dest are filled in from source
+    keyStringsToLanguageMappings keys do:[:eachKey |
+        |newXlation|
+        
+        (keyStringsToLanguageMappings at:eachKey language:destLanguage) isEmptyOrNil ifTrue:[
+            newXlation := keyStringsToLanguageMappings at:eachKey language:sourceLanguage.
+            newXlation notNil ifTrue:[
+                self halt.
+                keyStringsToLanguageMappings at:eachKey language:destLanguage put:newXlation.
+            ]
+        ]
+    ]
+!
+
 openAboutThisApplication
     "This method was generated by the Browser.
      It will be invoked when the menu-item 'help-about' is selected."