Tools__InternationalLanguageTranslationEditor.st
author fm
Wed, 14 Jun 2006 11:14:54 +0200
changeset 2053 8440fcd83b7b
parent 2051 88d16a7d0bd9
child 2163 641467b2f522
permissions -rw-r--r--
2.1 felix
UTF8 by default
saveAll
cg@2015
     1
"{ Package: 'stx:libtool2' }"
cg@2015
     2
cg@2015
     3
"{ NameSpace: Tools }"
cg@2015
     4
cg@2015
     5
ApplicationModel subclass:#InternationalLanguageTranslationEditor
cg@2015
     6
	instanceVariableNames:'languagesList keyStringsToLanguageMappings languageTextHolder
cg@2015
     7
		originalTextHolder modified shownLanguages selectedKeyRow
cg@2015
     8
		showMissingTranslationsOnly
cg@2015
     9
		keyStringAndLanguageSelectionTableColumnDescriptionHolder
cg@2015
    10
		languageShownHolders dataSetView lastExtractedClass
cg@2015
    11
		lastExtractedApplicationClass stopApplicationIconVisibleHolder
cg@2015
    12
		monitoredApplication originalTextModifiedHolder
cg@2048
    13
		languageTextModifiedHolder languageTextAcceptHolder
cg@2048
    14
		inSingleFileMode lastExtractedProject lastLanguage
fm@2050
    15
		lastSelectedKey autoAcceptHolder languageEditor
fm@2050
    16
		selectedColIndexHolder exampleLanguageSelectionHolder
fm@2051
    17
		exampleLanguageTextHolder pastePreviousTranslationEnableHolder
fm@2053
    18
		searchForSimilarTranslationEnableHolder alwaysWriteUTF8Holder'
cg@2032
    19
	classVariableNames:'LastExtractedClass LastExtractedApplicationClass
cg@2032
    20
		LastExtractedProject'
cg@2015
    21
	poolDictionaries:''
cg@2015
    22
	category:'Interface-UIPainter'
cg@2015
    23
!
cg@2015
    24
cg@2015
    25
Object subclass:#AccessCollectingPseudoResourcePack
cg@2015
    26
	instanceVariableNames:'collectedKeys realResourcePack'
cg@2015
    27
	classVariableNames:''
cg@2015
    28
	poolDictionaries:''
cg@2015
    29
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    30
!
cg@2015
    31
cg@2015
    32
Collection subclass:#KeyStringsToLanguageMappings
cg@2032
    33
	instanceVariableNames:'keys keyInfo perLanguageInfo perLanguageMappings languageMappings
fm@2049
    34
		languages rowPerKey'
cg@2015
    35
	classVariableNames:''
cg@2015
    36
	poolDictionaries:''
cg@2015
    37
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    38
!
cg@2015
    39
cg@2015
    40
Object subclass:#LanguageMappingRow
cg@2015
    41
	instanceVariableNames:'key mappings'
cg@2015
    42
	classVariableNames:''
cg@2015
    43
	poolDictionaries:''
cg@2015
    44
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    45
!
cg@2015
    46
cg@2015
    47
Visitor subclass:#UISpecVisitor
cg@2015
    48
	instanceVariableNames:'translatedLabels'
cg@2015
    49
	classVariableNames:''
cg@2015
    50
	poolDictionaries:''
cg@2015
    51
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    52
!
cg@2015
    53
cg@2015
    54
!InternationalLanguageTranslationEditor class methodsFor:'documentation'!
cg@2015
    55
cg@2015
    56
documentation
cg@2015
    57
"
cg@2015
    58
    documentation to be added.
cg@2015
    59
cg@2015
    60
    [author:]
cg@2015
    61
        cg (cg@FUSI)
cg@2015
    62
cg@2015
    63
    [instance variables:]
cg@2015
    64
cg@2015
    65
    [class variables:]
cg@2015
    66
cg@2015
    67
    [see also:]
cg@2015
    68
cg@2015
    69
"
cg@2015
    70
!
cg@2015
    71
cg@2015
    72
examples
cg@2015
    73
"
cg@2015
    74
  Starting the application:
cg@2015
    75
                                                                [exBegin]
cg@2015
    76
    InternationalLanguageTranslationEditor open
cg@2015
    77
cg@2015
    78
                                                                [exEnd]
cg@2015
    79
cg@2015
    80
  more examples to be added:
cg@2015
    81
                                                                [exBegin]
cg@2015
    82
    ... add code fragment for 
cg@2015
    83
    ... executable example here ...
cg@2015
    84
                                                                [exEnd]
cg@2015
    85
"
cg@2015
    86
!
cg@2015
    87
cg@2015
    88
history
cg@2015
    89
    "Created: / 04-03-2006 / 09:07:19 / cg"
cg@2015
    90
! !
cg@2015
    91
cg@2015
    92
!InternationalLanguageTranslationEditor class methodsFor:'interface specs'!
cg@2015
    93
cg@2015
    94
windowSpec
cg@2015
    95
    "This resource specification was automatically generated
cg@2015
    96
     by the UIPainter of ST/X."
cg@2015
    97
cg@2015
    98
    "Do not manually edit this!! If it is corrupted,
cg@2015
    99
     the UIPainter may not be able to read the specification."
cg@2015
   100
cg@2015
   101
    "
cg@2048
   102
     UIPainter new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#windowSpec
cg@2048
   103
     Tools::InternationalLanguageTranslationEditor new openInterface:#windowSpec
cg@2048
   104
     Tools::InternationalLanguageTranslationEditor open
cg@2015
   105
    "
cg@2015
   106
cg@2015
   107
    <resource: #canvas>
cg@2015
   108
cg@2015
   109
    ^ 
cg@2015
   110
     #(FullSpec
cg@2015
   111
        name: windowSpec
cg@2015
   112
        window: 
cg@2015
   113
       (WindowSpec
cg@2015
   114
          label: 'InternationalLanguageTranslationEditor'
cg@2015
   115
          name: 'InternationalLanguageTranslationEditor'
cg@2015
   116
          min: (Point 10 10)
cg@2015
   117
          max: (Point 1024 768)
fm@2053
   118
          bounds: (Rectangle 0 0 778 614)
cg@2015
   119
          menu: mainMenu
cg@2015
   120
        )
cg@2015
   121
        component: 
cg@2015
   122
       (SpecCollection
cg@2015
   123
          collection: (
cg@2015
   124
           (MenuPanelSpec
cg@2015
   125
              name: 'ToolBar'
cg@2015
   126
              layout: (LayoutFrame 0 0 0 0 0 1 30 0)
cg@2015
   127
              menu: menuToolBar
cg@2015
   128
              textDefault: true
cg@2015
   129
            )
cg@2015
   130
           (VariableVerticalPanelSpec
fm@2050
   131
              name: 'VariableVerticalPanel2'
cg@2015
   132
              layout: (LayoutFrame 0 0 30 0 0 1 0 1)
cg@2015
   133
              component: 
cg@2015
   134
             (SpecCollection
cg@2015
   135
                collection: (
cg@2015
   136
                 (DataSetSpec
cg@2015
   137
                    name: 'KeyStringAndLanguageSelectionTable'
cg@2015
   138
                    model: selectedKeyRow
cg@2015
   139
                    hasHorizontalScrollBar: true
cg@2015
   140
                    hasVerticalScrollBar: true
cg@2015
   141
                    dataList: keyStringAndLanguageSelectionTable
cg@2015
   142
                    columnHolder: keyStringAndLanguageSelectionTableColumnDescriptionHolder
fm@2049
   143
                    beDependentOfRows: true
cg@2015
   144
                    columnAdaptor: yourself
cg@2015
   145
                    postBuildCallback: postBuildDataSet:
cg@2015
   146
                  )
fm@2050
   147
                 (VariableVerticalPanelSpec
fm@2050
   148
                    name: 'VariableVerticalPanel1'
cg@2015
   149
                    component: 
cg@2015
   150
                   (SpecCollection
cg@2015
   151
                      collection: (
fm@2050
   152
                       (ViewSpec
fm@2050
   153
                          name: 'Box1'
fm@2050
   154
                          component: 
fm@2050
   155
                         (SpecCollection
fm@2050
   156
                            collection: (
fm@2050
   157
                             (LabelSpec
fm@2050
   158
                                label: 'Original String (Key):'
fm@2050
   159
                                name: 'Label2'
fm@2050
   160
                                layout: (LayoutFrame 0 0 -2 0 0 1 28 0)
fm@2050
   161
                                translateLabel: true
fm@2050
   162
                                adjust: left
fm@2050
   163
                              )
fm@2050
   164
                             (TextEditorSpec
fm@2050
   165
                                name: 'OriginalText'
fm@2050
   166
                                layout: (LayoutFrame 0 0 27 0 0 1 -2 1)
fm@2050
   167
                                model: originalTextHolder
fm@2050
   168
                                hasHorizontalScrollBar: true
fm@2050
   169
                                hasVerticalScrollBar: true
fm@2050
   170
                                modifiedChannel: originalTextModifiedHolder
fm@2050
   171
                                acceptCallBack: languageTextAccepted
fm@2050
   172
                              )
fm@2050
   173
                             )
fm@2050
   174
                           
fm@2050
   175
                          )
cg@2015
   176
                        )
fm@2050
   177
                       (ViewSpec
fm@2050
   178
                          name: 'Box3'
fm@2050
   179
                          component: 
fm@2050
   180
                         (SpecCollection
fm@2050
   181
                            collection: (
fm@2050
   182
                             (LabelSpec
fm@2051
   183
                                label: 'Select Another Language as example:'
fm@2050
   184
                                name: 'Label3'
fm@2050
   185
                                layout: (LayoutFrame 0 0 -6 0 0 1 24 0)
fm@2050
   186
                                translateLabel: true
fm@2050
   187
                                adjust: left
fm@2050
   188
                              )
fm@2050
   189
                             (ComboBoxSpec
fm@2050
   190
                                name: 'ComboBox1'
fm@2050
   191
                                layout: (LayoutFrame 197 0 -2 0 322 0 18 0)
fm@2050
   192
                                model: exampleLanguageSelectionHolder
fm@2050
   193
                                immediateAccept: false
fm@2050
   194
                                acceptOnLeave: true
fm@2050
   195
                                acceptOnLostFocus: true
fm@2050
   196
                                acceptOnPointerLeave: false
fm@2050
   197
                                comboList: shownLanguages
fm@2050
   198
                                useIndex: false
fm@2050
   199
                              )
fm@2050
   200
                             (TextEditorSpec
fm@2050
   201
                                name: 'ExampleLanguageText'
fm@2051
   202
                                layout: (LayoutFrame 0 0 30 0 0 1 0 1)
fm@2050
   203
                                model: exampleLanguageTextHolder
fm@2050
   204
                                hasHorizontalScrollBar: true
fm@2050
   205
                                hasVerticalScrollBar: true
fm@2050
   206
                                isReadOnly: true
fm@2050
   207
                              )
fm@2050
   208
                             )
fm@2050
   209
                           
fm@2050
   210
                          )
fm@2050
   211
                        )
fm@2050
   212
                       (ViewSpec
fm@2050
   213
                          name: 'Box2'
fm@2050
   214
                          component: 
fm@2050
   215
                         (SpecCollection
fm@2050
   216
                            collection: (
fm@2050
   217
                             (LabelSpec
fm@2050
   218
                                label: 'Translated String:'
fm@2050
   219
                                name: 'Label1'
fm@2050
   220
                                layout: (LayoutFrame 0 0 0 0 0 1 30 0)
fm@2050
   221
                                translateLabel: true
fm@2050
   222
                                adjust: left
fm@2050
   223
                              )
fm@2050
   224
                             (TextEditorSpec
fm@2050
   225
                                name: 'LanguageText'
fm@2050
   226
                                layout: (LayoutFrame 0 0 30 0 0 1 0 1)
fm@2050
   227
                                model: languageTextHolder
fm@2050
   228
                                hasHorizontalScrollBar: true
fm@2050
   229
                                hasVerticalScrollBar: true
fm@2050
   230
                                acceptChannel: languageTextAcceptHolder
fm@2050
   231
                                modifiedChannel: languageTextModifiedHolder
fm@2050
   232
                                acceptCallBack: languageTextAccepted
fm@2050
   233
                                postBuildCallback: languageEditorBuilt:
fm@2050
   234
                              )
fm@2051
   235
                             (ActionButtonSpec
fm@2051
   236
                                label: 'Paste Previous'
fm@2051
   237
                                name: 'pastePreviousTranslation'
fm@2051
   238
                                layout: (LayoutOrigin 0 0.83085250338295 0 0.03448275862069)
fm@2051
   239
                                translateLabel: true
fm@2051
   240
                                model: pastePreviousTranslationInLanguageText
fm@2051
   241
                                enableChannel: pastePreviousTranslationEnableHolder
fm@2051
   242
                                disabledLogo: 'Paste Previous'
fm@2051
   243
                              )
fm@2050
   244
                             )
fm@2050
   245
                           
fm@2050
   246
                          )
cg@2015
   247
                        )
cg@2015
   248
                       )
cg@2015
   249
                     
cg@2015
   250
                    )
fm@2050
   251
                    handles: (Any 0.33333333333333 0.66666666666667 1.0)
cg@2015
   252
                  )
cg@2015
   253
                 )
cg@2015
   254
               
cg@2015
   255
              )
fm@2050
   256
              handles: (Any 0.5 1.0)
cg@2015
   257
            )
cg@2015
   258
           )
cg@2015
   259
         
cg@2015
   260
        )
cg@2015
   261
      )
cg@2015
   262
! !
cg@2015
   263
cg@2015
   264
!InternationalLanguageTranslationEditor class methodsFor:'menu specs'!
cg@2015
   265
cg@2015
   266
mainMenu
cg@2015
   267
    "This resource specification was automatically generated
cg@2015
   268
     by the MenuEditor of ST/X."
cg@2015
   269
cg@2015
   270
    "Do not manually edit this!! If it is corrupted,
cg@2015
   271
     the MenuEditor may not be able to read the specification."
cg@2015
   272
cg@2015
   273
    "
fm@2050
   274
     MenuEditor new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#mainMenu
fm@2050
   275
     (Menu new fromLiteralArrayEncoding:(Tools::InternationalLanguageTranslationEditor mainMenu)) startUp
cg@2015
   276
    "
cg@2015
   277
cg@2015
   278
    <resource: #menu>
cg@2015
   279
cg@2015
   280
    ^ 
cg@2015
   281
     #(Menu
cg@2015
   282
        (
cg@2015
   283
         (MenuItem
cg@2015
   284
            label: 'File'
cg@2015
   285
            translateLabel: true
cg@2015
   286
            submenu: 
cg@2015
   287
           (Menu
cg@2015
   288
              (
cg@2015
   289
               (MenuItem
cg@2015
   290
                  label: 'New'
cg@2015
   291
                  itemValue: menuNew
cg@2015
   292
                  translateLabel: true
cg@2015
   293
                )
cg@2015
   294
               (MenuItem
cg@2015
   295
                  label: '-'
cg@2015
   296
                )
cg@2015
   297
               (MenuItem
cg@2015
   298
                  label: 'Open Resource File...'
cg@2015
   299
                  itemValue: menuOpen
cg@2015
   300
                  translateLabel: true
cg@2015
   301
                )
cg@2015
   302
               (MenuItem
cg@2015
   303
                  label: '-'
cg@2015
   304
                )
cg@2015
   305
               (MenuItem
fm@2053
   306
                  label: 'Save All Resource Files'
fm@2053
   307
                  itemValue: menuSaveAll
fm@2053
   308
                  translateLabel: true
fm@2053
   309
                )
fm@2053
   310
               (MenuItem
cg@2015
   311
                  label: 'Save Resource File'
cg@2015
   312
                  itemValue: menuSave
cg@2015
   313
                  translateLabel: true
cg@2015
   314
                )
cg@2015
   315
               (MenuItem
cg@2015
   316
                  label: 'Save Resource File As...'
cg@2015
   317
                  itemValue: menuSaveAs
cg@2015
   318
                  translateLabel: true
cg@2015
   319
                )
cg@2015
   320
               (MenuItem
cg@2015
   321
                  label: '-'
cg@2015
   322
                )
cg@2015
   323
               (MenuItem
cg@2015
   324
                  label: 'Exit'
cg@2015
   325
                  itemValue: closeRequest
cg@2015
   326
                  translateLabel: true
cg@2015
   327
                )
cg@2015
   328
               )
cg@2015
   329
              nil
cg@2015
   330
              nil
cg@2015
   331
            )
cg@2015
   332
          )
cg@2015
   333
         (MenuItem
cg@2015
   334
            label: 'View'
cg@2015
   335
            translateLabel: true
cg@2015
   336
            submenu: 
cg@2015
   337
           (Menu
cg@2015
   338
              (
cg@2015
   339
               (MenuItem
cg@2015
   340
                  label: 'Show Missing Translations Only'
cg@2015
   341
                  translateLabel: true
cg@2015
   342
                  indication: showMissingTranslationsOnly
cg@2015
   343
                )
cg@2015
   344
               (MenuItem
cg@2015
   345
                  label: '-'
cg@2015
   346
                )
cg@2015
   347
               (MenuItem
cg@2015
   348
                  label: 'Shown Languages'
cg@2015
   349
                  translateLabel: true
cg@2015
   350
                  submenuChannel: shownLanguagesMenu
cg@2015
   351
                )
cg@2015
   352
               )
cg@2015
   353
              nil
cg@2015
   354
              nil
cg@2015
   355
            )
cg@2015
   356
          )
cg@2015
   357
         (MenuItem
cg@2015
   358
            label: 'Languages'
cg@2015
   359
            translateLabel: true
cg@2015
   360
            submenu: 
cg@2015
   361
           (Menu
cg@2015
   362
              (
cg@2015
   363
               (MenuItem
cg@2015
   364
                  label: 'Add Language...'
cg@2015
   365
                  itemValue: addLanguage
cg@2015
   366
                  translateLabel: true
cg@2015
   367
                )
cg@2015
   368
               (MenuItem
cg@2015
   369
                  label: 'Remove Language...'
cg@2015
   370
                  itemValue: removeLanguage
cg@2015
   371
                  translateLabel: true
cg@2015
   372
                )
cg@2015
   373
               )
cg@2015
   374
              nil
cg@2015
   375
              nil
cg@2015
   376
            )
cg@2015
   377
          )
cg@2015
   378
         (MenuItem
cg@2015
   379
            label: 'Translations'
cg@2015
   380
            translateLabel: true
cg@2015
   381
            submenu: 
cg@2015
   382
           (Menu
cg@2015
   383
              (
cg@2015
   384
               (MenuItem
cg@2015
   385
                  label: 'Add Translation...'
cg@2015
   386
                  itemValue: addTranslation
cg@2015
   387
                  translateLabel: true
cg@2015
   388
                )
cg@2015
   389
               (MenuItem
cg@2015
   390
                  label: 'Remove Translation...'
cg@2015
   391
                  itemValue: removeTranslation
cg@2015
   392
                  translateLabel: true
cg@2015
   393
                )
cg@2015
   394
               (MenuItem
cg@2015
   395
                  label: '-'
cg@2015
   396
                )
cg@2015
   397
               (MenuItem
cg@2015
   398
                  label: 'Extract from Class...'
cg@2015
   399
                  itemValue: extractTranslationsFromClass
cg@2015
   400
                  translateLabel: true
cg@2015
   401
                )
cg@2015
   402
               (MenuItem
cg@2032
   403
                  label: 'Extract from Project...'
cg@2032
   404
                  itemValue: extractTranslationsFromProject
cg@2032
   405
                  translateLabel: true
cg@2032
   406
                )
cg@2032
   407
               (MenuItem
cg@2032
   408
                  label: '-'
cg@2032
   409
                )
cg@2032
   410
               (MenuItem
cg@2015
   411
                  label: 'Run Application and Collect Translations...'
cg@2015
   412
                  itemValue: runApplicationAndCollectTranslations
cg@2015
   413
                  translateLabel: true
cg@2015
   414
                )
cg@2015
   415
               )
cg@2015
   416
              nil
cg@2015
   417
              nil
cg@2015
   418
            )
cg@2015
   419
          )
cg@2015
   420
         (MenuItem
fm@2050
   421
            label: 'Preferences'
fm@2050
   422
            translateLabel: true
fm@2050
   423
            submenu: 
fm@2050
   424
           (Menu
fm@2050
   425
              (
fm@2050
   426
               (MenuItem
fm@2050
   427
                  label: 'Auto Accept Changes'
fm@2050
   428
                  translateLabel: true
fm@2050
   429
                  indication: autoAcceptHolder
fm@2050
   430
                )
fm@2051
   431
               (MenuItem
fm@2051
   432
                  label: 'Search For Similar Translations'
fm@2051
   433
                  translateLabel: true
fm@2051
   434
                  indication: searchForSimilarTranslationEnableHolder
fm@2051
   435
                )
fm@2053
   436
               (MenuItem
fm@2053
   437
                  label: 'Always Write UTF8'
fm@2053
   438
                  translateLabel: true
fm@2053
   439
                  indication: alwaysWriteUTF8Holder
fm@2053
   440
                )
fm@2050
   441
               )
fm@2050
   442
              nil
fm@2050
   443
              nil
fm@2050
   444
            )
fm@2050
   445
          )
fm@2050
   446
         (MenuItem
cg@2015
   447
            label: 'Help'
cg@2015
   448
            translateLabel: true
cg@2015
   449
            startGroup: right
cg@2015
   450
            submenu: 
cg@2015
   451
           (Menu
cg@2015
   452
              (
cg@2015
   453
               (MenuItem
cg@2015
   454
                  label: 'Documentation'
cg@2015
   455
                  itemValue: openDocumentation
cg@2015
   456
                  translateLabel: true
cg@2015
   457
                )
cg@2015
   458
               (MenuItem
cg@2015
   459
                  label: '-'
cg@2015
   460
                )
cg@2015
   461
               (MenuItem
cg@2015
   462
                  label: 'About this Application...'
cg@2015
   463
                  itemValue: openAboutThisApplication
cg@2015
   464
                  translateLabel: true
cg@2015
   465
                )
cg@2015
   466
               )
cg@2015
   467
              nil
cg@2015
   468
              nil
cg@2015
   469
            )
cg@2015
   470
          )
cg@2015
   471
         )
cg@2015
   472
        nil
cg@2015
   473
        nil
cg@2015
   474
      )
cg@2015
   475
!
cg@2015
   476
fm@2051
   477
menuItemsEditLanguage
fm@2051
   478
    "This resource specification was automatically generated
fm@2051
   479
     by the MenuEditor of ST/X."
fm@2051
   480
fm@2051
   481
    "Do not manually edit this!! If it is corrupted,
fm@2051
   482
     the MenuEditor may not be able to read the specification."
fm@2051
   483
fm@2051
   484
    "
fm@2051
   485
     MenuEditor new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#menu
fm@2051
   486
     (Menu new fromLiteralArrayEncoding:(Tools::InternationalLanguageTranslationEditor menu)) startUp
fm@2051
   487
    "
fm@2051
   488
fm@2051
   489
    <resource: #menu>
fm@2051
   490
fm@2051
   491
    ^ 
fm@2051
   492
     #(Menu
fm@2051
   493
        (
fm@2051
   494
         (MenuItem
fm@2051
   495
            enabled: pastePreviousTranslationEnableHolder
fm@2051
   496
            label: 'Paste Previous Translation'
fm@2051
   497
            itemValue: pastePreviousTranslationInLanguageText
fm@2051
   498
            nameKey: pastePreviousTranslationInLanguageText
fm@2051
   499
            translateLabel: true
fm@2051
   500
          )
fm@2051
   501
         )
fm@2051
   502
        nil
fm@2051
   503
        nil
fm@2051
   504
      )
fm@2051
   505
!
fm@2051
   506
cg@2015
   507
menuToolBar
cg@2015
   508
    "This resource specification was automatically generated
cg@2015
   509
     by the MenuEditor of ST/X."
cg@2015
   510
cg@2015
   511
    "Do not manually edit this!! If it is corrupted,
cg@2015
   512
     the MenuEditor may not be able to read the specification."
cg@2015
   513
cg@2015
   514
    "
fm@2051
   515
     MenuEditor new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#menuToolBar
fm@2051
   516
     (Menu new fromLiteralArrayEncoding:(Tools::InternationalLanguageTranslationEditor menuToolBar)) startUp
cg@2015
   517
    "
cg@2015
   518
cg@2015
   519
    <resource: #menu>
cg@2015
   520
cg@2015
   521
    ^ 
cg@2015
   522
     #(Menu
cg@2015
   523
        (
cg@2015
   524
         (MenuItem
cg@2015
   525
            label: 'Save'
fm@2051
   526
            itemValue: menuSave
cg@2015
   527
            translateLabel: true
cg@2015
   528
            labelImage: (ResourceRetriever XPToolbarIconLibrary saveImageIcon)
cg@2015
   529
          )
cg@2015
   530
         (MenuItem
cg@2015
   531
            label: '-'
cg@2015
   532
          )
cg@2015
   533
         (MenuItem
cg@2015
   534
            label: 'Add Translation'
cg@2015
   535
            itemValue: addTranslation
cg@2015
   536
            translateLabel: true
cg@2015
   537
            labelImage: (ResourceRetriever XPToolbarIconLibrary newRowIcon)
cg@2015
   538
          )
cg@2015
   539
         (MenuItem
cg@2015
   540
            label: 'Remove Translation'
cg@2015
   541
            itemValue: removeTranslation
cg@2015
   542
            translateLabel: true
cg@2015
   543
            labelImage: (ResourceRetriever XPToolbarIconLibrary removeRowIcon)
cg@2015
   544
          )
cg@2015
   545
         (MenuItem
cg@2015
   546
            label: ''
cg@2015
   547
          )
cg@2015
   548
         (MenuItem
cg@2015
   549
            label: 'Stop Application'
cg@2015
   550
            itemValue: stopApplication
cg@2015
   551
            translateLabel: true
cg@2015
   552
            isVisible: stopApplicationIconVisibleHolder
cg@2015
   553
            labelImage: (ResourceRetriever XPToolbarIconLibrary stop16x16Icon)
cg@2015
   554
          )
cg@2015
   555
         )
cg@2015
   556
        nil
cg@2015
   557
        nil
cg@2015
   558
      )
cg@2015
   559
! !
cg@2015
   560
cg@2047
   561
!InternationalLanguageTranslationEditor class methodsFor:'tableColumns specs'!
cg@2047
   562
cg@2047
   563
keyTableColumn
cg@2047
   564
    "This resource specification was automatically generated
cg@2047
   565
     by the DataSetBuilder of ST/X."
cg@2047
   566
cg@2047
   567
    "Do not manually edit this!! If it is corrupted,
cg@2047
   568
     the DataSetBuilder may not be able to read the specification."
cg@2047
   569
cg@2047
   570
    "
cg@2047
   571
     DataSetBuilder new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#keyTableColumn
cg@2047
   572
    "
cg@2047
   573
cg@2047
   574
    <resource: #tableColumns>
cg@2047
   575
cg@2047
   576
    ^#(
cg@2047
   577
      (DataSetColumnSpec
cg@2047
   578
         label: 'Key'
cg@2047
   579
         labelButtonType: Button
cg@2047
   580
         minWidth: 50
cg@2047
   581
         model: keyStringInRow:
cg@2047
   582
       )
cg@2047
   583
      )
cg@2047
   584
!
cg@2047
   585
cg@2047
   586
languageTableColumn
cg@2047
   587
    "This resource specification was automatically generated
cg@2047
   588
     by the DataSetBuilder of ST/X."
cg@2047
   589
cg@2047
   590
    "Do not manually edit this!! If it is corrupted,
cg@2047
   591
     the DataSetBuilder may not be able to read the specification."
cg@2047
   592
cg@2047
   593
    "
fm@2049
   594
     DataSetBuilder new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#languageTableColumn
cg@2047
   595
    "
cg@2047
   596
cg@2047
   597
    <resource: #tableColumns>
cg@2047
   598
cg@2047
   599
    ^#(
fm@2049
   600
      (DataSetColumnSpec
fm@2049
   601
         label: lang
fm@2049
   602
         labelButtonType: Button
fm@2049
   603
         minWidth: 50
fm@2049
   604
         editorType: None
fm@2049
   605
         model: columnInRow:at:
fm@2049
   606
         backgroundSelector: getBackgroundForRow:rowNr:col:
fm@2049
   607
       )
fm@2049
   608
      )
fm@2049
   609
! !
cg@2047
   610
fm@2049
   611
!InternationalLanguageTranslationEditor methodsFor:'accessing'!
fm@2049
   612
fm@2049
   613
newLanguageText
fm@2049
   614
"/   languageEditor accept
fm@2049
   615
^self languageTextHolder value isNil 
fm@2049
   616
    ifTrue:['']
fm@2049
   617
    ifFalse:[self languageTextHolder value asCollectionOfLines first.]
fm@2050
   618
!
fm@2050
   619
fm@2050
   620
selectedKey  
fm@2050
   621
   "Returns the current selected key if there is one row seleted. Otherwise, returns nil"
fm@2050
   622
     |rowSelectionIndex |
fm@2050
   623
fm@2050
   624
    rowSelectionIndex := self selectedKeyRow value.
fm@2050
   625
    rowSelectionIndex == 0 ifTrue:[^nil].
fm@2050
   626
    ^ keyStringsToLanguageMappings keyAt:rowSelectionIndex.
cg@2047
   627
! !
cg@2047
   628
fm@2051
   629
!InternationalLanguageTranslationEditor methodsFor:'additionalFuncionalities'!
fm@2051
   630
fm@2051
   631
searchForSimilarTranslation
fm@2051
   632
"Looks for a quite similar translation for the key and display a dialog with available options"
fm@2051
   633
|similarTranslationsAssociations selectedTranslation|
fm@2051
   634
fm@2051
   635
self shouldSearchForSimilarTranslation ifFalse:[^self]. 
fm@2051
   636
fm@2051
   637
similarTranslationsAssociations := keyStringsToLanguageMappings searchForSimilarTranslation: self selectedKey in: self currentLanguage.
fm@2051
   638
similarTranslationsAssociations isEmpty ifTrue:[^self].    
fm@2051
   639
fm@2051
   640
similarTranslationsAssociations := similarTranslationsAssociations associations inject: OrderedCollection new into:[:collection :association |
fm@2051
   641
    collection detect:[:selectedAssociation |
fm@2051
   642
        selectedAssociation value sameAs: association value] ifNone:[collection add: association].
fm@2051
   643
    collection].
fm@2051
   644
selectedTranslation := Dialog 
fm@2051
   645
    choose:'Choose one if you consider it´s usefull to translate: 
fm@2051
   646
', 
fm@2051
   647
    '<', self selectedKey, '>  ',
fm@2051
   648
    self currentExampleLanguageText
fm@2051
   649
    fromList: (similarTranslationsAssociations collect:[:each |  '<', each key, '>  ', each value])
fm@2051
   650
    values: (similarTranslationsAssociations collect:[:each | each value])
fm@2051
   651
    lines:10
fm@2051
   652
    cancel: nil.      
fm@2051
   653
fm@2051
   654
selectedTranslation notNil ifTrue:[self languageTextHolderValue: selectedTranslation]. 
fm@2051
   655
! !
fm@2051
   656
cg@2015
   657
!InternationalLanguageTranslationEditor methodsFor:'aspects'!
cg@2015
   658
fm@2053
   659
alwaysWriteUTF8Holder
fm@2053
   660
    alwaysWriteUTF8Holder isNil ifTrue:[alwaysWriteUTF8Holder := true asValue]. 
fm@2053
   661
    ^ alwaysWriteUTF8Holder
fm@2053
   662
!
fm@2053
   663
fm@2050
   664
autoAcceptHolder
fm@2050
   665
    autoAcceptHolder isNil ifTrue:[autoAcceptHolder := true asValue]. 
fm@2050
   666
    ^ autoAcceptHolder
fm@2050
   667
!
fm@2050
   668
fm@2050
   669
exampleLanguageSelectionHolder
fm@2050
   670
    exampleLanguageSelectionHolder isNil ifTrue:[
fm@2050
   671
        exampleLanguageSelectionHolder := self exampleLanguageByDefault asValue.         
fm@2050
   672
        exampleLanguageSelectionHolder addDependent:self.
fm@2050
   673
    ]. 
fm@2050
   674
    ^ exampleLanguageSelectionHolder
fm@2050
   675
!
fm@2050
   676
fm@2050
   677
exampleLanguageTextHolder
fm@2050
   678
    exampleLanguageTextHolder isNil ifTrue:[
fm@2050
   679
        exampleLanguageTextHolder := '' asValue.
fm@2050
   680
    ].
fm@2050
   681
    ^ exampleLanguageTextHolder.
fm@2050
   682
!
fm@2050
   683
cg@2015
   684
keyStringAndLanguageSelectionTable
cg@2015
   685
    keyStringsToLanguageMappings isNil ifTrue:[
cg@2015
   686
        keyStringsToLanguageMappings := KeyStringsToLanguageMappings new.
cg@2015
   687
    ].
cg@2015
   688
    ^ keyStringsToLanguageMappings.
cg@2015
   689
!
cg@2015
   690
cg@2015
   691
keyStringAndLanguageSelectionTableColumnDescriptionHolder
cg@2015
   692
    keyStringAndLanguageSelectionTableColumnDescriptionHolder isNil ifTrue:[
cg@2015
   693
        keyStringAndLanguageSelectionTableColumnDescriptionHolder := ValueHolder new.
cg@2015
   694
        keyStringAndLanguageSelectionTableColumnDescriptionHolder value:(self keyStringAndLanguageSelectionTableColumnDescription).
cg@2015
   695
    ].
cg@2015
   696
    ^ keyStringAndLanguageSelectionTableColumnDescriptionHolder.
cg@2015
   697
!
cg@2015
   698
cg@2015
   699
languageAtCol:colNr
cg@2015
   700
    ^ shownLanguages at:colNr-1.
cg@2015
   701
!
cg@2015
   702
cg@2015
   703
languageShownHolderFor:lang
cg@2015
   704
    |holder|
cg@2015
   705
cg@2015
   706
    languageShownHolders isNil ifTrue:[
cg@2015
   707
        languageShownHolders := Dictionary new
cg@2015
   708
    ].
cg@2015
   709
    holder := languageShownHolders 
cg@2015
   710
                at:lang 
cg@2015
   711
                ifAbsentPut:[ 
cg@2015
   712
                    |h|
cg@2015
   713
cg@2015
   714
                    h := true asValue.
cg@2015
   715
                    h onChangeEvaluate:[ 
cg@2015
   716
                        h value ifTrue:[
cg@2015
   717
                           self enableLanguageDisplayFor:lang     
cg@2015
   718
                        ] ifFalse:[
cg@2015
   719
                           self disableLanguageDisplayFor:lang     
cg@2015
   720
                        ].
cg@2015
   721
                    ].
cg@2015
   722
                    h
cg@2015
   723
                ].
cg@2015
   724
    ^ holder.
cg@2015
   725
!
cg@2015
   726
cg@2048
   727
languageTextAcceptHolder
cg@2048
   728
    languageTextAcceptHolder isNil ifTrue:[
fm@2050
   729
        languageTextAcceptHolder := false asValue.                        
cg@2048
   730
    ].
cg@2048
   731
    ^ languageTextAcceptHolder.
cg@2048
   732
!
cg@2048
   733
cg@2015
   734
languageTextHolder
cg@2015
   735
    languageTextHolder isNil ifTrue:[
cg@2015
   736
        languageTextHolder := '' asValue.
cg@2015
   737
    ].
cg@2015
   738
    ^ languageTextHolder.
cg@2015
   739
!
cg@2015
   740
cg@2015
   741
languageTextModifiedHolder
cg@2015
   742
    languageTextModifiedHolder isNil ifTrue:[
cg@2015
   743
        languageTextModifiedHolder := false asValue.
cg@2015
   744
    ].
cg@2015
   745
    ^ languageTextModifiedHolder.
cg@2015
   746
!
cg@2015
   747
cg@2015
   748
languagesList
cg@2015
   749
    languagesList isNil ifTrue:[
cg@2015
   750
        languagesList := List withAll:(self keyStringAndLanguageSelectionTable languages).
cg@2015
   751
    ].
cg@2015
   752
    ^ languagesList.
cg@2015
   753
!
cg@2015
   754
cg@2015
   755
originalTextHolder
cg@2015
   756
    originalTextHolder isNil ifTrue:[
cg@2015
   757
        originalTextHolder := '' asValue.
cg@2015
   758
    ].
cg@2015
   759
    ^ originalTextHolder.
cg@2015
   760
!
cg@2015
   761
cg@2015
   762
originalTextModifiedHolder
cg@2015
   763
    originalTextModifiedHolder isNil ifTrue:[
cg@2015
   764
        originalTextModifiedHolder := false asValue.
cg@2015
   765
    ].
cg@2015
   766
    ^ originalTextModifiedHolder.
cg@2015
   767
!
cg@2015
   768
fm@2051
   769
pastePreviousTranslationEnableHolder
fm@2051
   770
   pastePreviousTranslationEnableHolder isNil ifTrue:[pastePreviousTranslationEnableHolder := false asValue]. 
fm@2051
   771
    ^ pastePreviousTranslationEnableHolder
fm@2051
   772
!
fm@2051
   773
fm@2051
   774
searchForSimilarTranslationEnableHolder
fm@2051
   775
   searchForSimilarTranslationEnableHolder isNil 
fm@2051
   776
        ifTrue:[searchForSimilarTranslationEnableHolder := true asValue]. 
fm@2051
   777
    ^ searchForSimilarTranslationEnableHolder
fm@2051
   778
!
fm@2051
   779
cg@2015
   780
selectedKeyRow
cg@2015
   781
    selectedKeyRow isNil ifTrue:[
cg@2015
   782
        selectedKeyRow := ValueHolder new.
cg@2015
   783
        selectedKeyRow onChangeSend:#selectionChanged to:self.
cg@2015
   784
    ].
cg@2015
   785
    ^ selectedKeyRow.
cg@2015
   786
!
cg@2015
   787
cg@2015
   788
showMissingTranslationsOnly
cg@2015
   789
    showMissingTranslationsOnly isNil ifTrue:[
cg@2015
   790
        showMissingTranslationsOnly := false asValue.
fm@2051
   791
        showMissingTranslationsOnly onChangeSend:#showMissingTranslationsOnlyChanged to:self.
cg@2015
   792
    ].
cg@2015
   793
    ^ showMissingTranslationsOnly.
cg@2015
   794
!
cg@2015
   795
cg@2015
   796
shownLanguages
cg@2015
   797
    shownLanguages isNil ifTrue:[
cg@2015
   798
        shownLanguages := List new.
cg@2015
   799
        shownLanguages addAll:(self languagesList).
cg@2015
   800
        shownLanguages onChangeSend:#shownLanguagesChanged to:self.
cg@2015
   801
    ].
cg@2015
   802
    ^ shownLanguages.
cg@2015
   803
!
cg@2015
   804
cg@2015
   805
stopApplicationIconVisibleHolder
cg@2015
   806
    stopApplicationIconVisibleHolder isNil ifTrue:[
cg@2015
   807
        stopApplicationIconVisibleHolder := false asValue.
cg@2015
   808
    ].
cg@2015
   809
    ^ stopApplicationIconVisibleHolder.
cg@2015
   810
! !
cg@2015
   811
cg@2048
   812
!InternationalLanguageTranslationEditor methodsFor:'change & update'!
cg@2048
   813
fm@2051
   814
languageTextHolderValue: aString
fm@2051
   815
fm@2051
   816
self languageTextHolder value: aString.
fm@2051
   817
self languageTextModifiedHolder value:true.
fm@2051
   818
!
fm@2051
   819
cg@2048
   820
update:something with:aParameter from:changedObject
cg@2048
   821
    changedObject == shownLanguages ifTrue:[
cg@2048
   822
         self shownLanguagesChanged.
cg@2048
   823
         ^ self.
cg@2048
   824
    ].
fm@2049
   825
    changedObject == languageTextAcceptHolder ifTrue:[
fm@2049
   826
         self updateLanguageTextModification.
fm@2049
   827
         ^ self.
fm@2049
   828
    ].
fm@2050
   829
    changedObject == exampleLanguageSelectionHolder ifTrue:[
fm@2050
   830
        self updateExampleLanguageText.
fm@2050
   831
        ^ self.
fm@2051
   832
    ].    
fm@2051
   833
    changedObject == showMissingTranslationsOnly ifTrue:[
fm@2051
   834
        self showMissingTranslationsOnlyChanged.
fm@2051
   835
        ^ self.
fm@2051
   836
    ]. 
fm@2051
   837
!
fm@2051
   838
fm@2051
   839
updateCopyPreviousTranslationButtonEnabled
fm@2051
   840
fm@2051
   841
 self pastePreviousTranslationEnableHolder value: self shouldCopyPreviousTranslationButtonBeEnabled
fm@2050
   842
!
fm@2050
   843
fm@2050
   844
updateExampleLanguageText
fm@2050
   845
fm@2050
   846
    self selectedKeyRow value isNil ifTrue:[^ self].
fm@2050
   847
    self exampleLanguageTextHolder value:self currentExampleLanguageText
fm@2049
   848
!
fm@2049
   849
fm@2049
   850
updateKeyStringsToLanguageMappings           
fm@2049
   851
fm@2049
   852
      keyStringsToLanguageMappings 
fm@2049
   853
        at:lastSelectedKey 
fm@2049
   854
        language:lastLanguage 
fm@2049
   855
        put: self newLanguageText.
fm@2049
   856
!
fm@2049
   857
fm@2050
   858
updateLanguageAndKeySelection
fm@2050
   859
fm@2050
   860
    self originalTextHolder value: self selectedKey.
fm@2051
   861
    self languageTextHolder value: (self languageTextFromSelectedKeyFor: self currentLanguage).
fm@2051
   862
    lastLanguage := self currentLanguage.
fm@2050
   863
    lastSelectedKey := self selectedKey. 
fm@2050
   864
!
fm@2050
   865
fm@2049
   866
updateLanguageTextModification 
fm@2049
   867
     self languageTextModifiedHolder value ifTrue:[ 
fm@2049
   868
        (self autoAccept or:[Dialog confirm:'Accept changed translation ?']) ifTrue:[
fm@2049
   869
            self languageTextModifiedHolder value:false.
fm@2049
   870
            self languageTextHolder value:languageEditor contents.
fm@2049
   871
            lastLanguage notNil ifTrue:[self updateKeyStringsToLanguageMappings.]
fm@2049
   872
        ]
fm@2049
   873
    ].
fm@2049
   874
!
fm@2049
   875
fm@2049
   876
updateOriginalTextModification
fm@2049
   877
fm@2049
   878
|answer|
fm@2049
   879
fm@2049
   880
    self originalTextModifiedHolder value ifTrue:[ 
fm@2049
   881
        answer := OptionBox 
fm@2049
   882
                      request:'Accept changed original text (key) ?' 
fm@2049
   883
                      label:'Original text (key) changed'
fm@2049
   884
                      image:(WarningBox iconBitmap)
fm@2049
   885
                      buttonLabels:#('Cancel' 'Accept' 'Accept As New')
fm@2049
   886
                      values:#(nil #accept #acceptAsNew)
fm@2049
   887
                      default:#acceptAsNew.
fm@2049
   888
fm@2049
   889
        answer isNil ifTrue:[^ self originalTextModifiedHolder value:false. ].
fm@2049
   890
        answer == #accept ifTrue:[
fm@2049
   891
self halt.        ].
fm@2049
   892
        answer == #acceptAsNew ifTrue:[
fm@2049
   893
self halt.        ].
fm@2049
   894
    ].
cg@2048
   895
! !
cg@2048
   896
fm@2050
   897
!InternationalLanguageTranslationEditor methodsFor:'dialogs'!
fm@2050
   898
fm@2051
   899
requestEncoderDialog
fm@2050
   900
fm@2051
   901
   |box val characterCollection|
fm@2051
   902
fm@2051
   903
    val := '' asValue.
fm@2051
   904
    box := Dialog new.
fm@2051
   905
    (box addTextLabel:'Select or write the encoder') adjust:#left.
fm@2051
   906
    box addVerticalSpace.
fm@2051
   907
    characterCollection := CharacterEncoder supportedExternalEncodings 
fm@2051
   908
        inject: OrderedCollection new
fm@2051
   909
        into:[:collection :each |
fm@2051
   910
            collection add: each first;
fm@2051
   911
                        yourself].
fm@2051
   912
    (box addComboBoxOn:val) list: characterCollection.
fm@2051
   913
    box addOkButton.
fm@2051
   914
    box open.
fm@2051
   915
    ^val value
fm@2051
   916
!
fm@2051
   917
fm@2051
   918
requestEncoderStringFor: lang
fm@2051
   919
  "Returns an encoder string and updates the language's info"
fm@2051
   920
    |encoderString encoder|
fm@2051
   921
    encoderString := self requestEncoderDialog.
fm@2051
   922
    encoderString notEmpty ifTrue:[
fm@2051
   923
        encoder := CharacterEncoder encoderFor: encoderString ifAbsent:nil.
fm@2051
   924
        encoder notNil ifTrue:[keyStringsToLanguageMappings atLanguage: lang putEncoder: encoder.].
fm@2051
   925
    ].
fm@2051
   926
    ^encoderString
fm@2050
   927
!
fm@2050
   928
fm@2050
   929
requestFilename  
fm@2050
   930
fm@2050
   931
    |aFilename|
fm@2050
   932
fm@2050
   933
    aFilename := Dialog 
fm@2050
   934
        requestFileName:'Name of resource file:'
fm@2050
   935
        default:nil 
fm@2050
   936
        pattern:'*.rs'.
fm@2050
   937
fm@2050
   938
    aFilename isEmptyOrNil ifTrue:[^ nil ].
fm@2050
   939
    ^aFilename asFilename
fm@2050
   940
!
fm@2050
   941
fm@2051
   942
requestFilenameFor: lang  
fm@2051
   943
  "Returns a filename to save the language resource and updates the language's info"
fm@2051
   944
    |aFilename|
fm@2051
   945
fm@2051
   946
    aFilename := Dialog 
fm@2051
   947
        requestFileName:'Name of resource file to save ', lang asString, ' :'
fm@2051
   948
        default:nil 
fm@2051
   949
        pattern:'*.rs'.
fm@2051
   950
fm@2051
   951
    aFilename isEmptyOrNil ifTrue:[^ nil ].
fm@2051
   952
    keyStringsToLanguageMappings atLanguage: lang putFilename: aFilename.
fm@2051
   953
    ^aFilename asFilename
fm@2051
   954
!
fm@2051
   955
fm@2050
   956
requestLanguage
fm@2050
   957
    ^ Dialog 
fm@2050
   958
        choose:'Which language do you want to save?'
fm@2050
   959
        fromList:languagesList
fm@2050
   960
        lines:10
fm@2050
   961
! !
fm@2050
   962
cg@2015
   963
!InternationalLanguageTranslationEditor methodsFor:'initialization & release'!
cg@2015
   964
cg@2015
   965
closeRequest
cg@2015
   966
    "asks for permission before closing"
cg@2015
   967
cg@2015
   968
    self hasUnsavedChanges ifTrue:[
cg@2015
   969
        (Dialog 
cg@2015
   970
            confirm:(resources string:'Close without saving ?')
cg@2015
   971
            default:false) ifFalse:[
cg@2015
   972
            ^ self
cg@2015
   973
        ]
cg@2015
   974
    ].
cg@2015
   975
cg@2015
   976
    super closeRequest
cg@2015
   977
!
cg@2015
   978
cg@2015
   979
initialize
cg@2015
   980
    modified := false.
cg@2031
   981
    inSingleFileMode := false.
cg@2015
   982
    super initialize
cg@2015
   983
!
cg@2015
   984
fm@2049
   985
languageEditorBuilt:aView
fm@2049
   986
    languageEditor := aView.
fm@2049
   987
!
fm@2049
   988
cg@2015
   989
postBuildDataSet:aView
fm@2049
   990
    dataSetView := aView.
fm@2049
   991
    aView selectedColIndexHolder onChangeSend:#selectionChanged to:self.
cg@2015
   992
! !
cg@2015
   993
cg@2015
   994
!InternationalLanguageTranslationEditor methodsFor:'menu actions'!
cg@2015
   995
cg@2015
   996
addLanguage
cg@2015
   997
    |lang|
cg@2015
   998
cg@2015
   999
    lang := Dialog request:'New language (ISO symbol):'.
cg@2015
  1000
    lang isEmptyOrNil ifTrue:[^ self].
fm@2053
  1001
    lang := lang asSymbol.
cg@2015
  1002
    (keyStringsToLanguageMappings includesLanguage:lang) ifTrue:[^ self ].
cg@2015
  1003
cg@2015
  1004
    keyStringsToLanguageMappings addLanguage:lang.
cg@2015
  1005
    self languagesList add:lang.
cg@2015
  1006
    self shownLanguages add:lang.
cg@2015
  1007
    modified := true.
cg@2015
  1008
!
cg@2015
  1009
cg@2015
  1010
addTranslation
cg@2015
  1011
    |key index|
cg@2015
  1012
cg@2015
  1013
    key := Dialog request:'New Key:'.
fm@2051
  1014
    key isEmpty ifTrue:[^self].
cg@2015
  1015
    (keyStringsToLanguageMappings includesKey:key) ifFalse:[
cg@2015
  1016
        keyStringsToLanguageMappings addKey:key.
cg@2015
  1017
        modified := true.
cg@2015
  1018
    ].
fm@2051
  1019
   index := keyStringsToLanguageMappings indexOfKey:key.
fm@2051
  1020
   self selectedKeyRow value:index
cg@2015
  1021
!
cg@2015
  1022
cg@2015
  1023
extractTranslationsFromClass
cg@2015
  1024
    |aClass newTranslations|
cg@2015
  1025
cg@2015
  1026
    aClass := Dialog 
cg@2015
  1027
                requestClass:'Class to extract translations from:'
cg@2015
  1028
                okLabel:'OK' 
cg@2015
  1029
                initialAnswer:(lastExtractedClass ? LastExtractedClass).
cg@2015
  1030
    aClass isNil ifTrue:[^ self ].
cg@2015
  1031
cg@2015
  1032
    lastExtractedClass := LastExtractedClass := aClass.
cg@2015
  1033
cg@2032
  1034
    newTranslations := self extractTranslationsFromClass:aClass.
cg@2032
  1035
    self addAllTranslations:newTranslations.
cg@2032
  1036
!
cg@2032
  1037
cg@2032
  1038
extractTranslationsFromProject
cg@2032
  1039
    |box projectID newTranslations|
cg@2032
  1040
cg@2032
  1041
    box := ListSelectionBox new.
cg@2032
  1042
"/    box useComboBoxWithList:(Smalltalk allProjectIDs).
cg@2032
  1043
    box title:(resources string:'Project to extract translations from:').
cg@2032
  1044
    box list:Smalltalk allProjectIDs.
cg@2032
  1045
    box okAction:[:sel | projectID := sel].
cg@2032
  1046
    box initialText:(lastExtractedProject ? LastExtractedProject).
cg@2032
  1047
    box label:'Find Translations in Project'.
cg@2032
  1048
cg@2032
  1049
    box showAtPointer.
cg@2032
  1050
cg@2032
  1051
    projectID notNil ifTrue:[
cg@2032
  1052
        projectID := projectID withoutSeparators asSymbol.
cg@2032
  1053
    ].
cg@2032
  1054
    projectID isEmptyOrNil ifTrue:[^ self ].
cg@2032
  1055
cg@2032
  1056
    lastExtractedProject := LastExtractedProject := projectID.
cg@2032
  1057
cg@2015
  1058
    newTranslations := Set new.
cg@2015
  1059
cg@2032
  1060
    Smalltalk allClassesDo:[:eachClass |
cg@2032
  1061
        eachClass theNonMetaclass package == projectID ifTrue:[
cg@2032
  1062
"/ eachClass isLoaded ifTrue:[ self halt. ].
cg@2032
  1063
            newTranslations addAll:( self extractTranslationsFromClass:eachClass theNonMetaclass).
cg@2032
  1064
        ]
cg@2015
  1065
    ].
cg@2015
  1066
cg@2032
  1067
    self addAllTranslations:newTranslations.
cg@2015
  1068
!
cg@2015
  1069
cg@2015
  1070
menuNew
cg@2015
  1071
    modified ifTrue:[
cg@2015
  1072
        (Dialog 
cg@2015
  1073
            confirm:(resources stringWithCRs:'Modified translations have not been changed.\\Create new translations set anyway ?')
cg@2015
  1074
            default:false) ifFalse:[^ self].
cg@2015
  1075
    ].
cg@2015
  1076
cg@2015
  1077
    keyStringsToLanguageMappings initialize.
cg@2015
  1078
    keyStringsToLanguageMappings changed.
cg@2015
  1079
cg@2015
  1080
    self languagesList contents:self keyStringAndLanguageSelectionTable languages.
cg@2015
  1081
    self shownLanguages contents:self keyStringAndLanguageSelectionTable languages.
cg@2015
  1082
    modified := false.
cg@2015
  1083
!
cg@2015
  1084
cg@2015
  1085
menuOpen
fm@2050
  1086
    |aFilename|
cg@2015
  1087
fm@2050
  1088
    aFilename := self requestFilename.
fm@2050
  1089
    aFilename isNil ifTrue:[^ self ].
fm@2050
  1090
    self readResourceFile:aFilename
cg@2015
  1091
!
cg@2015
  1092
cg@2015
  1093
menuSave
fm@2050
  1094
"Saves the language selected in the fileName from where the language resource was obtained."
fm@2053
  1095
    |lang|
cg@2015
  1096
fm@2050
  1097
    lang := self requestLanguage.
fm@2050
  1098
    lang isNil ifTrue:[^ self].
fm@2053
  1099
    self saveLanguage: lang
fm@2053
  1100
!
fm@2053
  1101
fm@2053
  1102
menuSaveAll
fm@2053
  1103
"Saves all the languages in the fileName from where the language resource was obtained."
fm@2053
  1104
    keyStringsToLanguageMappings languagesInUse do:[:each | self saveLanguage: each]. 
cg@2015
  1105
!
cg@2015
  1106
cg@2015
  1107
menuSaveAs
fm@2050
  1108
"Saves the language selected in the specified fileName."
fm@2050
  1109
     |lang aFilename|
cg@2015
  1110
fm@2050
  1111
    lang := self requestLanguage.
fm@2050
  1112
    lang isNil ifTrue:[^ self]. 
fm@2053
  1113
    aFilename := self requestFilenameFor:lang.
fm@2050
  1114
    aFilename isNil ifTrue:[^ self].
fm@2050
  1115
    self saveResourceFile:aFilename for:lang asSymbol
cg@2015
  1116
!
cg@2015
  1117
cg@2015
  1118
openAboutThisApplication
cg@2015
  1119
    "This method was generated by the Browser.
cg@2015
  1120
     It will be invoked when the menu-item 'help-about' is selected."
cg@2015
  1121
cg@2015
  1122
    "/ could open a customized aboutBox here ...
cg@2015
  1123
    super openAboutThisApplication
cg@2015
  1124
!
cg@2015
  1125
cg@2015
  1126
openDocumentation
cg@2015
  1127
    "This method was generated by the Browser.
cg@2015
  1128
     It will be invoked when the menu-item 'help-documentation' is selected."
cg@2015
  1129
cg@2015
  1130
    "/ change below as required ...
cg@2015
  1131
cg@2015
  1132
    "/ to open an HTML viewer on some document (under 'doc/online/<language>/' ):
cg@2015
  1133
    HTMLDocumentView openFullOnDocumentationFile:'TOP.html'.
cg@2015
  1134
cg@2015
  1135
    "/ add application-specific help files under the 'doc/online/<language>/help/appName'
cg@2015
  1136
    "/ directory, and open a viewer with:
cg@2015
  1137
    "/ HTMLDocumentView openFullOnDocumentationFile:'help/<MyApplication>/TOP.html'.
cg@2015
  1138
!
cg@2015
  1139
cg@2015
  1140
readResourceFile:aFilename
cg@2031
  1141
    |lang|
cg@2031
  1142
cg@2031
  1143
    lang := Dialog choose:'For which language ?' fromList:languagesList lines:10.
cg@2031
  1144
    lang isNil ifTrue:[^ self ].
cg@2031
  1145
cg@2031
  1146
    self readResourceFile:aFilename asLanguage:lang asSymbol
cg@2031
  1147
!
cg@2031
  1148
fm@2050
  1149
removeLanguage
fm@2050
  1150
    |lang|
cg@2015
  1151
fm@2050
  1152
    lang := Dialog choose:'Which language do you want to remove?' fromList:languagesList lines:10.
fm@2050
  1153
    lang isNil ifTrue:[^ self ].
fm@2050
  1154
    (Dialog confirm: 'Are you sure to remove the language ', lang ) ifTrue:[
fm@2050
  1155
          self languagesList remove:lang.
fm@2050
  1156
          self shownLanguages remove:lang.
fm@2050
  1157
    ].      
cg@2015
  1158
!
cg@2015
  1159
cg@2015
  1160
removeTranslation
cg@2015
  1161
    |rowSelectionIndex selectedKey|
cg@2015
  1162
cg@2015
  1163
    rowSelectionIndex := self selectedKeyRow value.
cg@2015
  1164
    rowSelectionIndex ~~ 0 ifTrue:[
cg@2015
  1165
        selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex ifAbsent:nil.
cg@2015
  1166
        (Dialog confirm:(resources string:'Really remove key %1' with:selectedKey)) ifTrue:[
cg@2015
  1167
            keyStringsToLanguageMappings removeKey:selectedKey.
cg@2015
  1168
        ].
cg@2015
  1169
    ].
cg@2015
  1170
!
cg@2015
  1171
cg@2015
  1172
runApplicationAndCollectTranslations
cg@2047
  1173
    |applicationClass newTranslations pseudoPack app startSelector|
cg@2015
  1174
cg@2015
  1175
    monitoredApplication notNil ifTrue:[
cg@2015
  1176
        monitoredApplication terminate.
cg@2015
  1177
        [monitoredApplication notNil] whileTrue:[
cg@2015
  1178
            Delay waitForSeconds:0.1
cg@2015
  1179
        ].
cg@2015
  1180
    ].
cg@2015
  1181
cg@2015
  1182
    applicationClass := Dialog 
cg@2015
  1183
                requestClass:'Application class to start and collect translations from:'
cg@2015
  1184
                okLabel:'OK' 
cg@2015
  1185
                initialAnswer:(lastExtractedApplicationClass ? LastExtractedApplicationClass ).
cg@2015
  1186
    applicationClass isNil ifTrue:[^ self ].
cg@2047
  1187
    applicationClass isNamespace ifTrue:[
cg@2047
  1188
        Dialog warn:'Entered class is a NameSpace'.
cg@2047
  1189
        ^ self.
cg@2047
  1190
    ].
cg@2047
  1191
cg@2047
  1192
    applicationClass isVisualStartable ifTrue:[
cg@2047
  1193
        startSelector := #open
cg@2047
  1194
    ] ifFalse:[
cg@2047
  1195
        startSelector := Dialog
cg@2047
  1196
                    request:'Entered class seems to be no application class. Ok to start using selector:'
cg@2047
  1197
                    initialAnswer:((applicationClass respondsTo:#'start')
cg@2047
  1198
                                        ifTrue:#'start'
cg@2047
  1199
                                        ifFalse:#'new')
cg@2047
  1200
                    okLabel:'START'
cg@2047
  1201
                    title:'Start Application'.
cg@2047
  1202
        startSelector isNil ifTrue:[
cg@2047
  1203
            ^ self
cg@2047
  1204
        ].
cg@2047
  1205
        startSelector := startSelector asSymbol.
cg@2047
  1206
    ].
cg@2015
  1207
cg@2015
  1208
    lastExtractedApplicationClass := LastExtractedApplicationClass := applicationClass.
cg@2015
  1209
cg@2015
  1210
    newTranslations := Set new.
cg@2015
  1211
cg@2015
  1212
    pseudoPack := AccessCollectingPseudoResourcePack new.
cg@2015
  1213
    pseudoPack realResourcePack:(applicationClass classResources).
cg@2015
  1214
cg@2015
  1215
    self stopApplicationIconVisibleHolder value:true.
cg@2015
  1216
cg@2015
  1217
    monitoredApplication := [
cg@2015
  1218
        [
cg@2015
  1219
            app := applicationClass new.
cg@2047
  1220
            app perform:startSelector.
cg@2015
  1221
            app window waitUntilVisible.
cg@2015
  1222
            app window waitUntilClosed.
cg@2015
  1223
        ] ensure:[
cg@2015
  1224
            app closeRequest.
cg@2015
  1225
            self stopApplicationIconVisibleHolder value:false.
cg@2015
  1226
            monitoredApplication := nil.
cg@2015
  1227
        ].
cg@2015
  1228
    ] fork.
cg@2015
  1229
! !
cg@2015
  1230
cg@2015
  1231
!InternationalLanguageTranslationEditor methodsFor:'menus dynamic'!
cg@2015
  1232
cg@2015
  1233
disableLanguageDisplayFor:lang
cg@2015
  1234
    self shownLanguages remove:lang ifAbsent:[]
cg@2015
  1235
!
cg@2015
  1236
cg@2015
  1237
enableLanguageDisplayFor:newLang
cg@2015
  1238
    |shownLanguagesInOrder|
cg@2015
  1239
cg@2015
  1240
    (self shownLanguages includes:newLang) ifFalse:[
cg@2048
  1241
"/        shownLanguagesInOrder := self languagesList
cg@2048
  1242
"/                                    select:[:lang | (self shownLanguages includes:lang)
cg@2048
  1243
"/                                                    or:[ lang = newLang ]].
cg@2048
  1244
"/        self shownLanguages contents:shownLanguagesInOrder.
cg@2048
  1245
        self shownLanguages add:newLang.
cg@2015
  1246
    ]
cg@2015
  1247
!
cg@2015
  1248
cg@2015
  1249
isLanguageShown:lang
cg@2015
  1250
    ^ self shownLanguages includes:lang
cg@2015
  1251
!
cg@2015
  1252
cg@2015
  1253
shownLanguagesMenu
cg@2015
  1254
    <resource: #programMenu >
cg@2015
  1255
cg@2015
  1256
    ^ [
cg@2015
  1257
        |m selected|
cg@2015
  1258
cg@2015
  1259
        m := Menu new.
cg@2015
  1260
cg@2015
  1261
        self languagesList do:[:lang |
cg@2015
  1262
            |item|
cg@2015
  1263
cg@2015
  1264
            item := MenuItem label:lang.
cg@2015
  1265
            item indication:(self languageShownHolderFor:lang).
cg@2015
  1266
            item hideMenuOnActivated:false.    
cg@2015
  1267
            m addItem:item.
cg@2015
  1268
        ].
cg@2015
  1269
        m
cg@2015
  1270
    ].
cg@2015
  1271
!
cg@2015
  1272
cg@2015
  1273
toggleLanguageDisplayFor:lang
cg@2015
  1274
    (self shownLanguages includes:lang) ifTrue:[
cg@2015
  1275
        self disableLanguageDisplayFor:lang
cg@2015
  1276
    ] ifFalse:[
cg@2015
  1277
        self enableLanguageDisplayFor:lang
cg@2015
  1278
    ].
cg@2015
  1279
! !
cg@2015
  1280
cg@2015
  1281
!InternationalLanguageTranslationEditor methodsFor:'private-key extraction'!
cg@2015
  1282
cg@2032
  1283
addAllTranslations:newTranslations
cg@2034
  1284
    |newTranslationKeys stringKeys nonStringKeys|
cg@2032
  1285
cg@2034
  1286
    newTranslationKeys := newTranslations select:[:k | k notEmpty and:[k isString not or:[k isBlank not]]].
cg@2032
  1287
    newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
cg@2034
  1288
    newTranslationKeys := newTranslationKeys 
cg@2034
  1289
                                collect:[:k | 
cg@2034
  1290
                                        (k endsWith:'...') ifTrue:[
cg@2034
  1291
                                            k copyWithoutLast:3.
cg@2034
  1292
                                        ] ifFalse:[
cg@2035
  1293
                                            ('.:?' includes:k last) ifTrue:[
cg@2034
  1294
                                                k copyWithoutLast:1.
cg@2034
  1295
                                            ] ifFalse:[
cg@2034
  1296
                                                k
cg@2034
  1297
                                        ]]].
cg@2034
  1298
    newTranslationKeys := newTranslationKeys asSet.
cg@2034
  1299
cg@2032
  1300
    newTranslationKeys notEmpty ifTrue:[
cg@2034
  1301
        stringKeys := newTranslationKeys select:[:k | k isString].
cg@2034
  1302
        nonStringKeys := newTranslationKeys select:[:k | k isString not].
cg@2034
  1303
cg@2034
  1304
        stringKeys := stringKeys asSortedCollection.
cg@2034
  1305
        keyStringsToLanguageMappings addKeys:stringKeys.
cg@2034
  1306
        keyStringsToLanguageMappings addKeys:nonStringKeys.
cg@2032
  1307
        modified := true.
cg@2032
  1308
    ].
cg@2032
  1309
!
cg@2032
  1310
cg@2032
  1311
extractTranslationsFromClass:aClass
cg@2032
  1312
    |newTranslations|
cg@2032
  1313
cg@2032
  1314
    newTranslations := Set new.
cg@2032
  1315
cg@2032
  1316
    self withWaitCursorDo:[
cg@2032
  1317
        "/ now, the hard part:
cg@2032
  1318
        "/ possible translations are in the specs,
cg@2032
  1319
        "/ and all arguments to (resources string:) messages.
cg@2032
  1320
        aClass instAndClassMethodsDo:[:eachMethod |
cg@2032
  1321
            newTranslations addAll:( self extractTranslationsFromMethod:eachMethod ).
cg@2032
  1322
        ].
cg@2032
  1323
    ].
cg@2032
  1324
    ^ newTranslations
cg@2032
  1325
!
cg@2032
  1326
cg@2015
  1327
extractTranslationsFromHelpSpecMethod:aMethod
cg@2015
  1328
    |codeStrings matcher parseTree resourceKeys|
cg@2015
  1329
cg@2015
  1330
    parseTree := RBParser 
cg@2015
  1331
            parseMethod:aMethod source 
cg@2015
  1332
            onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
cg@2015
  1333
                                  nil].
cg@2015
  1334
    parseTree isNil ifTrue:[^ #() ].
cg@2015
  1335
cg@2015
  1336
    codeStrings  := 
cg@2015
  1337
        #(
cg@2015
  1338
                '`@dict addPairsFrom: `#helpKeysAndStrings'
cg@2015
  1339
        ).
cg@2015
  1340
cg@2015
  1341
    resourceKeys := Set new.
cg@2015
  1342
cg@2015
  1343
    matcher := ParseTreeSearcher new.
cg@2015
  1344
    matcher 
cg@2015
  1345
        matchesAnyOf: codeStrings 
cg@2015
  1346
        do: [:aNode :answer |
cg@2015
  1347
                |sel argNode arg|
cg@2015
  1348
cg@2015
  1349
                sel := aNode selector.
cg@2015
  1350
                (sel startsWith:'addPairsFrom:') ifTrue:[
cg@2015
  1351
                    argNode := aNode arguments at:1.
cg@2015
  1352
                    argNode isLiteral ifTrue:[
cg@2015
  1353
                        arg := argNode value.
cg@2015
  1354
                        arg isArray ifTrue:[
cg@2015
  1355
                            arg doWithIndex:[:el :index |
cg@2015
  1356
                                index even ifTrue:[
cg@2015
  1357
                                    el isString ifTrue:[    
cg@2015
  1358
                                        resourceKeys add:el.
cg@2015
  1359
                                    ]
cg@2015
  1360
                                ].
cg@2015
  1361
                            ].
cg@2015
  1362
                        ] ifFalse:[
cg@2015
  1363
                            Transcript 
cg@2015
  1364
                                showCR:(resources 
cg@2015
  1365
                                        string:'Cannot derive resourceKey from non-array in %1 in %2'
cg@2015
  1366
                                        with:argNode formattedCode
cg@2015
  1367
                                        with:aMethod selector).
cg@2015
  1368
                        ].
cg@2015
  1369
                    ] ifFalse:[
cg@2015
  1370
                        Transcript 
cg@2015
  1371
                            showCR:(resources 
cg@2015
  1372
                                        string:'Cannot derive resourceKey from non-literal: %1 in %2'
cg@2015
  1373
                                        with:argNode formattedCode
cg@2015
  1374
                                        with:aMethod selector).
cg@2015
  1375
                    ].
cg@2015
  1376
                ].
cg@2015
  1377
                aNode
cg@2015
  1378
            ].
cg@2015
  1379
cg@2015
  1380
    matcher executeTree: parseTree initialAnswer: nil.
cg@2015
  1381
    ^ resourceKeys
cg@2015
  1382
!
cg@2015
  1383
cg@2015
  1384
extractTranslationsFromMenuSpecMethod:aMethod
cg@2015
  1385
    |menu resourceKeys|
cg@2015
  1386
cg@2015
  1387
    menu := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
  1388
    menu isNil ifTrue:[ ^ #() ].
cg@2015
  1389
cg@2015
  1390
    (menu isKindOf:Menu) ifFalse:[
cg@2015
  1391
        menu := Menu new fromLiteralArrayEncoding:menu
cg@2015
  1392
    ].
cg@2015
  1393
cg@2015
  1394
    resourceKeys := Set new.
cg@2015
  1395
    menu allItemsDo:[:aMenuItem |
cg@2015
  1396
        aMenuItem translateLabel ifTrue:[
cg@2015
  1397
            aMenuItem isSeparatorItem ifFalse:[
cg@2015
  1398
                resourceKeys add:aMenuItem label.
cg@2015
  1399
            ]
cg@2015
  1400
        ]
cg@2015
  1401
    ].
cg@2015
  1402
    ^ resourceKeys
cg@2015
  1403
!
cg@2015
  1404
cg@2015
  1405
extractTranslationsFromMethod:aMethod
cg@2015
  1406
    |mResources|
cg@2015
  1407
cg@2015
  1408
    mResources := aMethod resources.
cg@2015
  1409
    mResources notNil ifTrue:[
cg@2015
  1410
        (mResources includesKey:#menu) ifTrue:[
cg@2015
  1411
             ^ self extractTranslationsFromMenuSpecMethod:aMethod.
cg@2015
  1412
        ].
cg@2015
  1413
        (mResources includesKey:#canvas) ifTrue:[
cg@2015
  1414
             ^ self extractTranslationsFromUISpecMethod:aMethod.
cg@2015
  1415
        ].
cg@2015
  1416
        (mResources includesKey:#help) ifTrue:[
cg@2015
  1417
             ^ self extractTranslationsFromHelpSpecMethod:aMethod.
cg@2015
  1418
        ].
cg@2015
  1419
        (mResources includesKey:#tableColumns) ifTrue:[
cg@2015
  1420
             ^ self extractTranslationsFromTableColumnsSpecMethod:aMethod.
cg@2015
  1421
        ].
cg@2015
  1422
cg@2015
  1423
        ^ self extractTranslationsFromSpecMethod:aMethod.
cg@2015
  1424
    ].
cg@2015
  1425
    ^ self extractTranslationsFromMethodsCode:aMethod
cg@2015
  1426
!
cg@2015
  1427
cg@2015
  1428
extractTranslationsFromMethodsCode:aMethod
cg@2015
  1429
"/method:mthd selector:sel inClass:cls matchesParseTreeMatcher:aMatcher
cg@2015
  1430
    |codeStrings matcher parseTree resourceKeys|
cg@2015
  1431
cg@2015
  1432
    parseTree := RBParser 
cg@2015
  1433
            parseMethod:aMethod source 
cg@2015
  1434
            onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
cg@2015
  1435
                                  nil].
cg@2015
  1436
    parseTree isNil ifTrue:[^ #() ].
cg@2015
  1437
cg@2015
  1438
    codeStrings  := 
cg@2015
  1439
        #(
cg@2015
  1440
                'resources `@msg: `@args'
cg@2015
  1441
                'self resources `@msg: `@args'
cg@2015
  1442
                'self class resources `@msg: `@args'
cg@2015
  1443
                'self classResources `@msg: `@args'
cg@2015
  1444
        ).
cg@2015
  1445
cg@2015
  1446
    resourceKeys := Set new.
cg@2015
  1447
cg@2015
  1448
    matcher := ParseTreeSearcher new.
cg@2015
  1449
    matcher 
cg@2015
  1450
        matchesAnyOf: codeStrings 
cg@2015
  1451
        do: [:aNode :answer |
cg@2015
  1452
                |sel keyStringArgNode keyStringArg|
cg@2015
  1453
cg@2015
  1454
                sel := aNode selector.
cg@2015
  1455
                ((sel startsWith:'string:') or:[(sel startsWith:'at:')]) ifTrue:[
cg@2015
  1456
                    keyStringArgNode := aNode arguments at:1.
cg@2015
  1457
                    keyStringArgNode isLiteral ifTrue:[
cg@2015
  1458
                        keyStringArg := keyStringArgNode value.
cg@2015
  1459
                        keyStringArg isString ifTrue:[
cg@2015
  1460
                            resourceKeys add:keyStringArg.
cg@2015
  1461
                        ] ifFalse:[
cg@2015
  1462
                            Transcript 
cg@2015
  1463
                                showCR:(resources 
cg@2015
  1464
                                        string:'Cannot derive resourceKey from non-string: %1 in %2'
cg@2015
  1465
                                        with:keyStringArgNode formattedCode
cg@2015
  1466
                                        with:aMethod selector).
cg@2015
  1467
                        ].
cg@2015
  1468
                    ] ifFalse:[
cg@2015
  1469
                        Transcript 
cg@2015
  1470
                            showCR:(resources 
cg@2015
  1471
                                        string:'Cannot derive resourceKey from non-literal: %1 in %2'
cg@2015
  1472
                                        with:keyStringArgNode formattedCode
cg@2015
  1473
                                        with:aMethod selector).
cg@2015
  1474
                    ].
cg@2015
  1475
                ].
cg@2015
  1476
                aNode
cg@2015
  1477
            ].
cg@2015
  1478
cg@2015
  1479
    matcher executeTree: parseTree initialAnswer: nil.
cg@2015
  1480
    ^ resourceKeys
cg@2015
  1481
!
cg@2015
  1482
cg@2015
  1483
extractTranslationsFromSpecMethod:aMethod
cg@2015
  1484
    ^ #()
cg@2015
  1485
!
cg@2015
  1486
cg@2015
  1487
extractTranslationsFromTableColumnsSpecMethod:aMethod
cg@2015
  1488
    |columnDescription resourceKeys|
cg@2015
  1489
cg@2015
  1490
    columnDescription := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
  1491
    columnDescription isNil ifTrue:[ ^ #() ].
cg@2015
  1492
cg@2015
  1493
    (columnDescription first isKindOf:DataSetColumnSpec) ifFalse:[
cg@2015
  1494
        columnDescription := columnDescription collect:[:el | DataSetColumnSpec new fromLiteralArrayEncoding:el].
cg@2015
  1495
    ].
cg@2015
  1496
cg@2015
  1497
    resourceKeys := Set new.
cg@2015
  1498
    columnDescription do:[:aColumnSpec |
cg@2015
  1499
        aColumnSpec translateLabel ifTrue:[
cg@2015
  1500
            resourceKeys add:aColumnSpec label.
cg@2015
  1501
        ]
cg@2015
  1502
    ].
cg@2015
  1503
    ^ resourceKeys
cg@2015
  1504
!
cg@2015
  1505
cg@2015
  1506
extractTranslationsFromUISpecMethod:aMethod
cg@2015
  1507
    |spec resourceKeys visitor|
cg@2015
  1508
cg@2015
  1509
    spec := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
  1510
    spec isNil ifTrue:[ ^ #() ].
cg@2015
  1511
cg@2015
  1512
    (spec isKindOf:UISpecification) ifFalse:[
cg@2015
  1513
        spec := UISpecification from:spec
cg@2015
  1514
    ].
cg@2015
  1515
cg@2015
  1516
    resourceKeys := Set new.
cg@2015
  1517
cg@2015
  1518
    visitor := UISpecVisitor new.
cg@2015
  1519
    spec acceptVisitor:visitor.
cg@2015
  1520
cg@2015
  1521
    ^ visitor translatedLabels
cg@2015
  1522
! !
cg@2015
  1523
cg@2015
  1524
!InternationalLanguageTranslationEditor methodsFor:'queries'!
cg@2015
  1525
fm@2050
  1526
autoAccept                                                   
fm@2050
  1527
fm@2050
  1528
    ^ self autoAcceptHolder value
fm@2050
  1529
!
fm@2050
  1530
fm@2050
  1531
currentExampleLanguageText           
fm@2050
  1532
   "Returns the language text corresponding for the current selected key and the example language selection"
fm@2050
  1533
fm@2050
  1534
  ^self languageTextFromSelectedKeyFor: self exampleLanguageSelectionHolder value
fm@2050
  1535
!
fm@2050
  1536
fm@2051
  1537
currentLanguage
fm@2051
  1538
fm@2051
  1539
|colSelectionIndex |
fm@2051
  1540
fm@2051
  1541
    colSelectionIndex := dataSetView selectedColIndex.
fm@2051
  1542
    ^colSelectionIndex > 1 ifTrue:[ shownLanguages at:colSelectionIndex-1 ] ifFalse:nil.
fm@2051
  1543
!
fm@2051
  1544
fm@2050
  1545
exampleLanguageByDefault
fm@2050
  1546
fm@2050
  1547
^self shownLanguages isEmpty
fm@2050
  1548
    ifTrue:[nil]
fm@2050
  1549
    ifFalse:[self shownLanguages first]
fm@2050
  1550
!
fm@2050
  1551
fm@2051
  1552
hasFirstRowSelection
fm@2051
  1553
    self selectedKeyRow isNil ifTrue:[^false].
fm@2051
  1554
    ^ self selectedKeyRow value > 1
fm@2051
  1555
!
fm@2051
  1556
fm@2051
  1557
hasLanguageSelection
fm@2051
  1558
    dataSetView selectedColIndex isNil ifTrue:[^false].
fm@2051
  1559
    ^ dataSetView selectedColIndex > 1
fm@2051
  1560
!
fm@2051
  1561
cg@2015
  1562
hasUnsavedChanges
cg@2015
  1563
    ^ modified
fm@2050
  1564
!
fm@2050
  1565
fm@2051
  1566
isSearchForSimilarTranslationEnabled
fm@2051
  1567
fm@2051
  1568
^self searchForSimilarTranslationEnableHolder value
fm@2051
  1569
!
fm@2051
  1570
fm@2051
  1571
languageTextFromKey: aKeyIndex for: language
fm@2051
  1572
    "Returns the language text corresponding for the aKeyIndex and the received language"    
fm@2051
  1573
fm@2051
  1574
    language isNil ifTrue:[^''].
fm@2051
  1575
    ^keyStringsToLanguageMappings at: aKeyIndex language:language.   
fm@2051
  1576
!
fm@2051
  1577
fm@2050
  1578
languageTextFromSelectedKeyFor: language
fm@2050
  1579
    "Returns the language text corresponding for the current selected key and the received language"    
fm@2050
  1580
fm@2051
  1581
    ^self languageTextFromKey: self selectedKey for: language 
fm@2051
  1582
!
fm@2051
  1583
fm@2051
  1584
shouldCopyPreviousTranslationButtonBeEnabled
fm@2051
  1585
    ^ self hasLanguageSelection 
fm@2051
  1586
        and:[self hasFirstRowSelection]
fm@2051
  1587
!
fm@2051
  1588
fm@2051
  1589
shouldSearchForSimilarTranslation
fm@2051
  1590
fm@2051
  1591
self isSearchForSimilarTranslationEnabled ifFalse:[^false].
fm@2051
  1592
(self languageTextHolder value notNil and:[self languageTextHolder value notEmpty]) ifTrue:[^false].
fm@2051
  1593
(self hasLanguageSelection and:[self selectedKeyRow notNil]) ifFalse:[^false].
fm@2051
  1594
^true
fm@2050
  1595
! !
fm@2050
  1596
fm@2050
  1597
!InternationalLanguageTranslationEditor methodsFor:'read/write resourceFile'!
fm@2050
  1598
fm@2053
  1599
encoderAt: lang
fm@2053
  1600
fm@2053
  1601
self alwaysWriteUTF8Holder value ifTrue:[^CharacterEncoder encoderForUTF8].
fm@2053
  1602
^keyStringsToLanguageMappings encoderAt: lang.
fm@2053
  1603
!
fm@2053
  1604
fm@2050
  1605
printEditingWarningOn: aStream
fm@2050
  1606
fm@2050
  1607
aStream nextPutAll: ';';
fm@2050
  1608
        cr;
fm@2050
  1609
        nextPutAll: '; WARNING:';
fm@2050
  1610
        cr;
fm@2050
  1611
        nextPutAll: '; this file contains national characters';
fm@2050
  1612
        cr;
fm@2050
  1613
        nextPutAll: '; DONT EDIT this file with an old vi !!';
fm@2050
  1614
        cr;
fm@2050
  1615
        nextPutAll: ';';
fm@2051
  1616
        cr; 
fm@2050
  1617
        cr.
fm@2050
  1618
!
fm@2050
  1619
fm@2050
  1620
printEncoderFor: lang on: aStream
fm@2050
  1621
|characterEncoder encoderString|
fm@2050
  1622
fm@2053
  1623
characterEncoder := self encoderAt: lang.
fm@2050
  1624
encoderString := characterEncoder isNil 
fm@2051
  1625
    ifTrue:[self requestEncoderStringFor: lang]
fm@2050
  1626
    ifFalse:[characterEncoder nameOfEncoding printString].
fm@2050
  1627
fm@2050
  1628
aStream nextPutAll: '#encoding';
fm@2050
  1629
        space;
fm@2050
  1630
        nextPutAll: encoderString;
fm@2050
  1631
        cr;
fm@2050
  1632
        cr.
fm@2050
  1633
!
fm@2050
  1634
fm@2050
  1635
printLanguage: lang on: aStream
fm@2050
  1636
fm@2050
  1637
self printEncoderFor: lang on: aStream.
fm@2050
  1638
self printEditingWarningOn: aStream.
fm@2050
  1639
self printLanguageMappingsFor: lang on: aStream.
fm@2050
  1640
!
fm@2050
  1641
fm@2050
  1642
printLanguageMappingsFor: lang on: aStream
fm@2050
  1643
fm@2053
  1644
|orderedAssociations maxKeySize characterEncoder|   
fm@2050
  1645
fm@2053
  1646
characterEncoder := self encoderAt: lang.
fm@2053
  1647
characterEncoder isNil ifTrue:[ characterEncoder := CharacterEncoder::NullEncoder ].
fm@2051
  1648
orderedAssociations := keyStringsToLanguageMappings orderedLanguageMappingsAssociationsFor: lang. 
fm@2050
  1649
fm@2051
  1650
maxKeySize := keyStringsToLanguageMappings maxKeySizeForLanguage: lang.     
fm@2050
  1651
fm@2051
  1652
orderedAssociations do:[:association |
fm@2051
  1653
    aStream nextPutAll: (association key storeString paddedTo: maxKeySize) ; 
fm@2051
  1654
        nextPutAll: (String new: 10);
fm@2053
  1655
        nextPutAll: (characterEncoder encodeString: association value) storeString;
fm@2050
  1656
        cr.
fm@2050
  1657
    ].
fm@2050
  1658
!
fm@2050
  1659
fm@2050
  1660
readResourceFile:aFilename asLanguage:lang
fm@2050
  1661
    |resourcePack inStream lineString encoding decoder sortedKeys remainingKeys|
fm@2050
  1662
fm@2050
  1663
    aFilename exists ifFalse:[^ self ].
fm@2050
  1664
fm@2050
  1665
    resourcePack := ResourcePack new.
fm@2050
  1666
fm@2050
  1667
    inStream := aFilename readStream.
fm@2050
  1668
    [inStream atEnd] whileFalse:[
fm@2050
  1669
        lineString := inStream nextLine.
fm@2050
  1670
        (lineString notEmpty 
fm@2050
  1671
        and:[ (lineString startsWith:';') not ]) ifTrue:[
fm@2050
  1672
            ((lineString startsWith:'#') and:[(lineString startsWith:'#(') not]) ifTrue:[
fm@2050
  1673
                lineString := (lineString copyFrom:2) withoutSeparators.
fm@2050
  1674
                (lineString startsWith:'encoding ') ifTrue:[
fm@2050
  1675
                    encoding := ResourcePack extractEncodingFromLine:lineString.
fm@2050
  1676
                    decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil.
fm@2050
  1677
                ].
fm@2050
  1678
            ] ifFalse:[
fm@2050
  1679
                ResourcePack
fm@2050
  1680
                    processResourceLine:lineString 
fm@2050
  1681
                    encoding:decoder 
fm@2050
  1682
                    file:aFilename pathName 
fm@2050
  1683
                    printErrorWith:[:msg | Transcript showCR:msg ] 
fm@2050
  1684
                    for:resourcePack
fm@2050
  1685
                    keepUselessTranslations:true.
fm@2050
  1686
            ].
fm@2050
  1687
        ].
fm@2050
  1688
    ].
fm@2050
  1689
    inStream close.                                                  
fm@2050
  1690
fm@2050
  1691
    sortedKeys := (resourcePack keys select:[:k | k isString]) asSortedCollection.
fm@2050
  1692
    remainingKeys := resourcePack keys select:[:k | k isString not].
fm@2050
  1693
fm@2050
  1694
    keyStringsToLanguageMappings atLanguage: lang putFilename: aFilename.
fm@2050
  1695
    keyStringsToLanguageMappings  atLanguage: lang putEncoder: decoder.
fm@2050
  1696
fm@2050
  1697
    sortedKeys do:[:k |
fm@2050
  1698
        keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k)
fm@2050
  1699
    ].
fm@2050
  1700
    remainingKeys do:[:k |
fm@2050
  1701
        keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k)
fm@2050
  1702
    ].
fm@2050
  1703
!
fm@2050
  1704
fm@2053
  1705
saveLanguage: lang
fm@2053
  1706
"Saves the language in the fileName from where the language resource was obtained."
fm@2053
  1707
    |aFilename|
fm@2053
  1708
fm@2053
  1709
    lang isNil ifTrue:[^ self].
fm@2053
  1710
    aFilename := keyStringsToLanguageMappings filenameAt:lang.
fm@2053
  1711
    aFilename isNil ifTrue:[
fm@2053
  1712
        aFilename := self requestFilenameFor: lang.
fm@2053
  1713
        aFilename isNil ifTrue:[^ self].
fm@2053
  1714
    ].
fm@2053
  1715
    self saveResourceFile:aFilename for:lang asSymbol
fm@2053
  1716
!
fm@2053
  1717
fm@2050
  1718
saveResourceFile: aFilename for: lang
fm@2050
  1719
fm@2050
  1720
|aStream |
fm@2050
  1721
fm@2051
  1722
keyStringsToLanguageMappings atLanguage: lang putFilename: aFilename.
fm@2051
  1723
aStream := FileStream newFileNamed: aFilename.  
fm@2050
  1724
self printLanguage: lang on: aStream.
fm@2050
  1725
aStream flush;
fm@2050
  1726
        close.
fm@2050
  1727
DialogBox information: 'The resource file for the language ', lang printString storeString, ' was saved in the file: ', aFilename nameString
cg@2015
  1728
! !
cg@2015
  1729
cg@2015
  1730
!InternationalLanguageTranslationEditor methodsFor:'specs-dynamic'!
cg@2015
  1731
cg@2015
  1732
columnInRow:row at:colIndex
cg@2015
  1733
    |lang|
cg@2015
  1734
cg@2015
  1735
    lang := self languageAtCol:colIndex.
cg@2015
  1736
    ^ row atLanguage:lang
cg@2015
  1737
!
cg@2015
  1738
cg@2015
  1739
getBackgroundForRow:row rowNr:rowNr col:colIndex
cg@2015
  1740
    |lang|
cg@2015
  1741
cg@2015
  1742
    colIndex == 1 ifTrue:[^ nil].
cg@2015
  1743
    lang := self languageAtCol:colIndex.
cg@2015
  1744
    ^ (row atLanguage:lang) isNil ifTrue:[Color red lightened] ifFalse:nil
cg@2015
  1745
!
cg@2015
  1746
cg@2015
  1747
keyStringAndLanguageSelectionTableColumnDescription
cg@2015
  1748
    |spec|
cg@2015
  1749
cg@2015
  1750
    spec := OrderedCollection new.
cg@2015
  1751
cg@2047
  1752
    spec add:(self class keyTableColumn first).
cg@2015
  1753
cg@2015
  1754
    self shownLanguages do:[:lang |
cg@2015
  1755
        |entry|
cg@2015
  1756
cg@2047
  1757
        entry := self class languageTableColumn first.
cg@2047
  1758
        entry := entry copy replaceAll:#lang with:lang.
cg@2015
  1759
        spec add: entry 
cg@2015
  1760
    ].
cg@2015
  1761
    ^ spec
cg@2015
  1762
!
cg@2015
  1763
cg@2015
  1764
keyStringInRow:row
cg@2015
  1765
    ^ row keyString
cg@2015
  1766
! !
cg@2015
  1767
cg@2015
  1768
!InternationalLanguageTranslationEditor methodsFor:'user actions'!
cg@2015
  1769
fm@2050
  1770
exampleLanguageSelectionChanged
fm@2050
  1771
fm@2050
  1772
   self updateExampleLanguageText.
fm@2050
  1773
!
fm@2050
  1774
fm@2051
  1775
languageTextAccepted                                   
fm@2051
  1776
|nextRowIndex|
fm@2051
  1777
keyStringsToLanguageMappings size = self selectedKeyRow value
fm@2051
  1778
    ifTrue:[ self updateLanguageTextModification.]
fm@2051
  1779
    ifFalse:[ 
fm@2051
  1780
        nextRowIndex := self selectedKeyRow value + 1.
fm@2051
  1781
        self selectedKeyRow value: nextRowIndex].
fm@2051
  1782
!
fm@2051
  1783
fm@2051
  1784
pastePreviousTranslationInLanguageText
fm@2051
  1785
    "Obtain the text from the previous translation and paste it into the languageTextEditor"
fm@2051
  1786
    
fm@2051
  1787
    | previousLanguageText previousLanguageRow|
fm@2051
  1788
fm@2051
  1789
    previousLanguageRow := dataSetView at:self selectedKeyRow value - 1
fm@2051
  1790
                ifAbsent:[^self].
fm@2051
  1791
    previousLanguageText := previousLanguageRow atLanguage: self currentLanguage.
fm@2051
  1792
    languageEditor selectAll.
fm@2051
  1793
    languageEditor pasteOrReplace:previousLanguageText.
fm@2051
  1794
    self languageTextModifiedHolder value:true.
fm@2051
  1795
!
fm@2051
  1796
fm@2049
  1797
selectionChanged                
cg@2048
  1798
fm@2049
  1799
   self updateOriginalTextModification.
fm@2049
  1800
   self updateLanguageTextModification.
fm@2049
  1801
   self updateLanguageAndKeySelection.
fm@2050
  1802
   self updateExampleLanguageText.
cg@2048
  1803
fm@2051
  1804
   self updateCopyPreviousTranslationButtonEnabled.
fm@2051
  1805
fm@2049
  1806
   self originalTextModifiedHolder value:false.
fm@2049
  1807
   self languageTextModifiedHolder value:false.
fm@2051
  1808
fm@2051
  1809
   self searchForSimilarTranslation.
fm@2051
  1810
!
fm@2051
  1811
fm@2051
  1812
showMissingTranslationsOnlyChanged
cg@2015
  1813
!
cg@2015
  1814
cg@2015
  1815
shownLanguagesChanged
cg@2015
  1816
    self keyStringAndLanguageSelectionTableColumnDescriptionHolder 
cg@2015
  1817
        value:(self keyStringAndLanguageSelectionTableColumnDescription).
cg@2015
  1818
!
cg@2015
  1819
cg@2015
  1820
stopApplication
cg@2015
  1821
    |p|
cg@2015
  1822
cg@2015
  1823
    (p := monitoredApplication) notNil ifTrue:[
cg@2015
  1824
        p terminate.
cg@2015
  1825
    ].
cg@2015
  1826
! !
cg@2015
  1827
cg@2015
  1828
!InternationalLanguageTranslationEditor::AccessCollectingPseudoResourcePack methodsFor:'accessing'!
cg@2015
  1829
cg@2015
  1830
realResourcePack:something
cg@2015
  1831
    realResourcePack := something.
cg@2015
  1832
! !
cg@2015
  1833
cg@2015
  1834
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings class methodsFor:'instance creation'!
cg@2015
  1835
cg@2015
  1836
new
cg@2015
  1837
    ^ self basicNew initialize
cg@2015
  1838
! !
cg@2015
  1839
cg@2015
  1840
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'accessing'!
cg@2015
  1841
cg@2015
  1842
addKey:aKey
cg@2031
  1843
    (keys includes:aKey) ifFalse:[
cg@2031
  1844
        keys add:aKey.
cg@2031
  1845
        self changed.
cg@2031
  1846
    ]
cg@2015
  1847
!
cg@2015
  1848
cg@2015
  1849
addKeys:aCollectionOfKey
cg@2015
  1850
    keys addAll:aCollectionOfKey.
cg@2015
  1851
    self changed.
cg@2015
  1852
!
cg@2015
  1853
cg@2015
  1854
addLanguage:lang
cg@2031
  1855
    (languages includes:lang) ifFalse:[
cg@2031
  1856
        languages add:lang.
fm@2051
  1857
        perLanguageMappings at:lang put:(OrderedDictionary new).
cg@2031
  1858
    ]
cg@2015
  1859
!
cg@2015
  1860
cg@2015
  1861
at:aKey language:language
cg@2032
  1862
    ^ (perLanguageMappings at:language) at:aKey ifAbsent:nil
cg@2015
  1863
!
cg@2015
  1864
cg@2015
  1865
at:aKey language:language put:value
cg@2015
  1866
    self addKey:aKey.
fm@2049
  1867
    (perLanguageMappings at:language) at:aKey put:value.
fm@2049
  1868
    (self rowForKey:aKey) changed
cg@2015
  1869
!
cg@2015
  1870
fm@2050
  1871
atLanguage: lang putEncoder: aDecoder
fm@2050
  1872
fm@2050
  1873
^(self languageInfoAt: lang) at: self encoderKey put: aDecoder
fm@2050
  1874
!
fm@2050
  1875
fm@2050
  1876
atLanguage: lang putFilename: aFilename
fm@2050
  1877
fm@2050
  1878
^(self languageInfoAt: lang) at: self fileNameKey put: aFilename
fm@2050
  1879
!
fm@2050
  1880
fm@2050
  1881
decoderKey
fm@2050
  1882
   ^#decoder
fm@2050
  1883
!
fm@2050
  1884
fm@2050
  1885
encoderAt:lang 
fm@2050
  1886
    ^ (self languageInfoAt:lang) at: self encoderKey ifAbsent:[nil]
fm@2050
  1887
!
fm@2050
  1888
fm@2050
  1889
encoderKey
fm@2050
  1890
   ^#encoder
fm@2050
  1891
!
fm@2050
  1892
fm@2050
  1893
fileNameKey
fm@2050
  1894
    ^ #filename
fm@2050
  1895
!
fm@2050
  1896
fm@2050
  1897
filenameAt:lang 
fm@2050
  1898
    ^ (self languageInfoAt:lang) at: self fileNameKey ifAbsent:[nil]
fm@2050
  1899
!
fm@2050
  1900
cg@2015
  1901
keyAt:index
fm@2051
  1902
    ^ keys at:index ifAbsent:[nil].
cg@2015
  1903
!
cg@2015
  1904
cg@2015
  1905
keyAt:index ifAbsent:exceptionalValue
cg@2015
  1906
    ^ keys at:index ifAbsent:exceptionalValue.
cg@2015
  1907
!
cg@2015
  1908
cg@2015
  1909
keys
cg@2015
  1910
    ^ keys
cg@2015
  1911
!
cg@2015
  1912
fm@2050
  1913
languageInfoAt: lang 
fm@2050
  1914
fm@2050
  1915
^self perLanguageInfo at: lang ifAbsentPut:[Dictionary new]
fm@2050
  1916
!
fm@2050
  1917
cg@2015
  1918
languages
cg@2015
  1919
    ^ languages
cg@2015
  1920
!
cg@2015
  1921
fm@2053
  1922
languagesInUse
fm@2053
  1923
"Returns a collection of symbols for the languages that have mappings"
fm@2053
  1924
fm@2053
  1925
^self languages select:[:each | (self atLanguage: each) notEmpty]
fm@2053
  1926
!
fm@2053
  1927
fm@2051
  1928
orderedLanguageMappingsAssociationsFor: language
fm@2051
  1929
"Returns a collection of languageMappings associations (alphabetically ordered by keys) "
fm@2051
  1930
^(self atLanguage: language) associations asSortedCollection:[:a :b | a key < b key].
fm@2051
  1931
!
fm@2051
  1932
fm@2050
  1933
perLanguageInfo
fm@2050
  1934
    ^ perLanguageInfo
fm@2050
  1935
!
fm@2050
  1936
fm@2050
  1937
perLanguageInfo:something
fm@2050
  1938
    perLanguageInfo := something.
fm@2050
  1939
!
fm@2050
  1940
cg@2015
  1941
removeKey:aKey
cg@2015
  1942
    keys remove:aKey ifAbsent:[].
cg@2032
  1943
    perLanguageMappings do:[:eachMapping |
cg@2015
  1944
        eachMapping removeKey:aKey ifAbsent:[].
cg@2015
  1945
    ].
cg@2015
  1946
    self changed.
cg@2015
  1947
!
cg@2015
  1948
fm@2049
  1949
rowForKey:aKey
fm@2049
  1950
    ^ rowPerKey 
fm@2049
  1951
            at:aKey
fm@2049
  1952
            ifAbsentPut:[InternationalLanguageTranslationEditor::LanguageMappingRow new 
fm@2049
  1953
                            key:aKey; mappings:self].
fm@2049
  1954
!
fm@2049
  1955
cg@2015
  1956
size
cg@2015
  1957
    ^ keys size
cg@2015
  1958
! !
cg@2015
  1959
cg@2015
  1960
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'enumerating'!
cg@2015
  1961
cg@2015
  1962
do:aBlock
cg@2015
  1963
    keys do:[:eachKey |
fm@2049
  1964
        aBlock value:(self rowForKey:eachKey).
cg@2015
  1965
    ].
cg@2015
  1966
! !
cg@2015
  1967
cg@2015
  1968
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'initialization'!
cg@2015
  1969
cg@2015
  1970
initialize
cg@2015
  1971
    super initialize.
cg@2015
  1972
cg@2015
  1973
    keys := OrderedSet new.
cg@2015
  1974
    languages := OrderedCollection new.
cg@2032
  1975
    perLanguageMappings := Dictionary new.
fm@2050
  1976
    perLanguageInfo := Dictionary new.         
fm@2049
  1977
    rowPerKey := Dictionary new.
cg@2015
  1978
cg@2031
  1979
    self addLanguage:#'de'.
cg@2031
  1980
    self addLanguage:#'fr'.
cg@2031
  1981
    self addLanguage:#'es'.
cg@2031
  1982
    self addLanguage:(Smalltalk language).
cg@2031
  1983
cg@2031
  1984
    "/ self initializeDemoMappings.
cg@2031
  1985
!
cg@2031
  1986
cg@2031
  1987
initializeDemoMappings
cg@2015
  1988
    keys add:'open'.
cg@2015
  1989
    keys add:'close'.
cg@2015
  1990
    keys add:'yes'.
cg@2015
  1991
    keys add:'no'.
cg@2015
  1992
cg@2015
  1993
    self addLanguage:#'de'.
cg@2015
  1994
    self addLanguage:#'fr'.
cg@2015
  1995
cg@2015
  1996
    self at:'open' language:#'de' put:'öffnen'.    
cg@2015
  1997
    self at:'close' language:#'de' put:'schliessen'.    
cg@2015
  1998
    self at:'yes' language:#'de' put:'ja'.    
cg@2015
  1999
    self at:'no' language:#'de' put:'nein'.    
cg@2015
  2000
    self at:'cancel' language:#'de' put:'abbrechen'.    
cg@2015
  2001
cg@2015
  2002
    self at:'open' language:#'fr' put:'ouvrir'.    
cg@2015
  2003
    self at:'close' language:#'fr' put:'fermer'.    
cg@2015
  2004
    self at:'yes' language:#'fr' put:'oui'.    
cg@2015
  2005
    self at:'no' language:#'fr' put:'non'.    
cg@2015
  2006
! !
cg@2015
  2007
cg@2015
  2008
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'private'!
cg@2015
  2009
cg@2015
  2010
atLanguage:lang
cg@2032
  2011
    ^ perLanguageMappings at:lang
cg@2015
  2012
!
cg@2015
  2013
cg@2015
  2014
atLanguageIndex:idx
cg@2015
  2015
    |lang|
cg@2015
  2016
cg@2015
  2017
    lang := languages at:idx.
cg@2015
  2018
    ^ self atLanguage:lang.
cg@2032
  2019
!
cg@2032
  2020
cg@2032
  2021
mappingAtLanguage:lang
cg@2032
  2022
    ^ perLanguageMappings at:lang
cg@2032
  2023
!
cg@2032
  2024
cg@2032
  2025
mappingAtLanguageIndex:idx
cg@2032
  2026
    |lang|
cg@2032
  2027
cg@2032
  2028
    lang := languages at:idx.
cg@2032
  2029
    ^ self mappingAtLanguage:lang.
cg@2015
  2030
! !
cg@2015
  2031
cg@2015
  2032
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'queries'!
cg@2015
  2033
cg@2015
  2034
includesKey:aKey
cg@2015
  2035
    ^ keys includes:aKey
cg@2015
  2036
!
cg@2015
  2037
cg@2015
  2038
includesLanguage:lang
cg@2015
  2039
    ^ languages includes:lang
cg@2015
  2040
!
cg@2015
  2041
cg@2015
  2042
indexOfKey:aKey
cg@2015
  2043
    ^ keys indexOf:aKey
fm@2050
  2044
!
fm@2050
  2045
fm@2050
  2046
maxKeySizeForLanguage: lang
fm@2050
  2047
fm@2050
  2048
^(self atLanguage: lang) keys inject: 0 into:[:maxSize :each |
fm@2051
  2049
    (maxSize < each size and:[each size < 100])
fm@2050
  2050
        ifTrue:[each size]
fm@2050
  2051
        ifFalse:[maxSize].].
fm@2051
  2052
!
fm@2051
  2053
fm@2051
  2054
searchForSimilarTranslation: aKey in: language
fm@2051
  2055
"Returns a collection of translation associations that corresponds to a quite similar key comparing with aKey"
fm@2051
  2056
|similarAssociations|
fm@2051
  2057
similarAssociations:= 
fm@2051
  2058
(self mappingAtLanguage: language) associationsSelect:[:each |
fm@2051
  2059
    ((each key sameAs: aKey) 
fm@2051
  2060
        or:[(aKey asUppercase startsWith: each key asUppercase)
fm@2051
  2061
            or:[((each key asUppercase levenshteinTo: aKey asUppercase)/ each key size) < 0.3
fm@2051
  2062
            ]])
fm@2051
  2063
     and:[each value notNil
fm@2051
  2064
            and:[each value notEmpty]]
fm@2051
  2065
].
fm@2051
  2066
^similarAssociations
cg@2015
  2067
! !
cg@2015
  2068
cg@2015
  2069
!InternationalLanguageTranslationEditor::LanguageMappingRow methodsFor:'accessing'!
cg@2015
  2070
cg@2015
  2071
atLanguage:language
cg@2032
  2072
    |translation|
cg@2032
  2073
cg@2032
  2074
    translation := (mappings mappingAtLanguage:language) at:key ifAbsent:nil.
cg@2032
  2075
    ^ translation isNil ifTrue:nil ifFalse:[translation printString]
cg@2015
  2076
!
cg@2015
  2077
cg@2015
  2078
columnAt:columnNr
cg@2032
  2079
    ^ (mappings mappingAtLanguageIndex:columnNr-1) at: key ifAbsent:nil
cg@2015
  2080
!
cg@2015
  2081
cg@2015
  2082
key:something
cg@2015
  2083
    key := something.
cg@2015
  2084
!
cg@2015
  2085
cg@2015
  2086
keyString
cg@2032
  2087
    ^ key printString
cg@2015
  2088
!
cg@2015
  2089
cg@2015
  2090
mappings:something
cg@2015
  2091
    mappings := something.
cg@2015
  2092
! !
cg@2015
  2093
cg@2015
  2094
!InternationalLanguageTranslationEditor::UISpecVisitor methodsFor:'accessing'!
cg@2015
  2095
cg@2015
  2096
translatedLabels
cg@2015
  2097
    ^ translatedLabels ? #()
cg@2015
  2098
! !
cg@2015
  2099
cg@2015
  2100
!InternationalLanguageTranslationEditor::UISpecVisitor methodsFor:'visiting'!
cg@2015
  2101
cg@2015
  2102
visitObject:anObject with:aParameter
cg@2033
  2103
    |l|
cg@2033
  2104
cg@2015
  2105
    (anObject isKindOf:UISpecification) ifTrue:[
cg@2015
  2106
        (anObject respondsTo:#translateLabel) ifTrue:[
cg@2015
  2107
            anObject translateLabel == true ifTrue:[
cg@2015
  2108
                translatedLabels isNil ifTrue:[
cg@2015
  2109
                    translatedLabels := Set new.
cg@2015
  2110
                ].
cg@2033
  2111
                l := anObject perform:#label ifNotUnderstood:nil.
cg@2033
  2112
                l notNil ifTrue:[
cg@2033
  2113
                    translatedLabels add:l.
cg@2033
  2114
                ].
cg@2015
  2115
            ].
cg@2015
  2116
        ].
cg@2015
  2117
    ].
cg@2015
  2118
    self visitChildrenOf:anObject.
cg@2015
  2119
! !
cg@2015
  2120
cg@2015
  2121
!InternationalLanguageTranslationEditor class methodsFor:'documentation'!
cg@2015
  2122
cg@2015
  2123
version
cg@2015
  2124
    ^ '$Header$'
cg@2015
  2125
! !