Tools__InternationalLanguageTranslationEditor.st
author Claus Gittinger <cg@exept.de>
Mon, 06 Mar 2006 20:25:39 +0100
changeset 2034 23d558e4d32e
parent 2033 2c1264ae2c1c
child 2035 ea8ec7c3fbeb
permissions -rw-r--r--
*** empty log message ***
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@2032
    13
		languageTextModifiedHolder inSingleFileMode lastExtractedProject'
cg@2032
    14
	classVariableNames:'LastExtractedClass LastExtractedApplicationClass
cg@2032
    15
		LastExtractedProject'
cg@2015
    16
	poolDictionaries:''
cg@2015
    17
	category:'Interface-UIPainter'
cg@2015
    18
!
cg@2015
    19
cg@2015
    20
Object subclass:#AccessCollectingPseudoResourcePack
cg@2015
    21
	instanceVariableNames:'collectedKeys realResourcePack'
cg@2015
    22
	classVariableNames:''
cg@2015
    23
	poolDictionaries:''
cg@2015
    24
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    25
!
cg@2015
    26
cg@2015
    27
Collection subclass:#KeyStringsToLanguageMappings
cg@2032
    28
	instanceVariableNames:'keys keyInfo perLanguageInfo perLanguageMappings languageMappings
cg@2032
    29
		languages'
cg@2015
    30
	classVariableNames:''
cg@2015
    31
	poolDictionaries:''
cg@2015
    32
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    33
!
cg@2015
    34
cg@2015
    35
Object subclass:#LanguageMappingRow
cg@2015
    36
	instanceVariableNames:'key mappings'
cg@2015
    37
	classVariableNames:''
cg@2015
    38
	poolDictionaries:''
cg@2015
    39
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    40
!
cg@2015
    41
cg@2015
    42
Visitor subclass:#UISpecVisitor
cg@2015
    43
	instanceVariableNames:'translatedLabels'
cg@2015
    44
	classVariableNames:''
cg@2015
    45
	poolDictionaries:''
cg@2015
    46
	privateIn:InternationalLanguageTranslationEditor
cg@2015
    47
!
cg@2015
    48
cg@2015
    49
!InternationalLanguageTranslationEditor class methodsFor:'documentation'!
cg@2015
    50
cg@2015
    51
documentation
cg@2015
    52
"
cg@2015
    53
    documentation to be added.
cg@2015
    54
cg@2015
    55
    [author:]
cg@2015
    56
        cg (cg@FUSI)
cg@2015
    57
cg@2015
    58
    [instance variables:]
cg@2015
    59
cg@2015
    60
    [class variables:]
cg@2015
    61
cg@2015
    62
    [see also:]
cg@2015
    63
cg@2015
    64
"
cg@2015
    65
!
cg@2015
    66
cg@2015
    67
examples
cg@2015
    68
"
cg@2015
    69
  Starting the application:
cg@2015
    70
                                                                [exBegin]
cg@2015
    71
    InternationalLanguageTranslationEditor open
cg@2015
    72
cg@2015
    73
                                                                [exEnd]
cg@2015
    74
cg@2015
    75
  more examples to be added:
cg@2015
    76
                                                                [exBegin]
cg@2015
    77
    ... add code fragment for 
cg@2015
    78
    ... executable example here ...
cg@2015
    79
                                                                [exEnd]
cg@2015
    80
"
cg@2015
    81
!
cg@2015
    82
cg@2015
    83
history
cg@2015
    84
    "Created: / 04-03-2006 / 09:07:19 / cg"
cg@2015
    85
! !
cg@2015
    86
cg@2015
    87
!InternationalLanguageTranslationEditor class methodsFor:'interface specs'!
cg@2015
    88
cg@2015
    89
windowSpec
cg@2015
    90
    "This resource specification was automatically generated
cg@2015
    91
     by the UIPainter of ST/X."
cg@2015
    92
cg@2015
    93
    "Do not manually edit this!! If it is corrupted,
cg@2015
    94
     the UIPainter may not be able to read the specification."
cg@2015
    95
cg@2015
    96
    "
cg@2015
    97
     UIPainter new openOnClass:InternationalLanguageTranslationEditor andSelector:#windowSpec
cg@2015
    98
     InternationalLanguageTranslationEditor new openInterface:#windowSpec
cg@2015
    99
     InternationalLanguageTranslationEditor open
cg@2015
   100
    "
cg@2015
   101
cg@2015
   102
    <resource: #canvas>
cg@2015
   103
cg@2015
   104
    ^ 
cg@2015
   105
     #(FullSpec
cg@2015
   106
        name: windowSpec
cg@2015
   107
        window: 
cg@2015
   108
       (WindowSpec
cg@2015
   109
          label: 'InternationalLanguageTranslationEditor'
cg@2015
   110
          name: 'InternationalLanguageTranslationEditor'
cg@2015
   111
          min: (Point 10 10)
cg@2015
   112
          max: (Point 1024 768)
cg@2015
   113
          bounds: (Rectangle 0 0 640 400)
cg@2015
   114
          menu: mainMenu
cg@2015
   115
        )
cg@2015
   116
        component: 
cg@2015
   117
       (SpecCollection
cg@2015
   118
          collection: (
cg@2015
   119
           (MenuPanelSpec
cg@2015
   120
              name: 'ToolBar'
cg@2015
   121
              layout: (LayoutFrame 0 0 0 0 0 1 30 0)
cg@2015
   122
              menu: menuToolBar
cg@2015
   123
              textDefault: true
cg@2015
   124
            )
cg@2015
   125
           (VariableVerticalPanelSpec
cg@2015
   126
              name: 'VariableVerticalPanel1'
cg@2015
   127
              layout: (LayoutFrame 0 0 30 0 0 1 0 1)
cg@2015
   128
              component: 
cg@2015
   129
             (SpecCollection
cg@2015
   130
                collection: (
cg@2015
   131
                 (DataSetSpec
cg@2015
   132
                    name: 'KeyStringAndLanguageSelectionTable'
cg@2015
   133
                    model: selectedKeyRow
cg@2015
   134
                    hasHorizontalScrollBar: true
cg@2015
   135
                    hasVerticalScrollBar: true
cg@2015
   136
                    dataList: keyStringAndLanguageSelectionTable
cg@2015
   137
                    columnHolder: keyStringAndLanguageSelectionTableColumnDescriptionHolder
cg@2015
   138
                    columnAdaptor: yourself
cg@2015
   139
                    postBuildCallback: postBuildDataSet:
cg@2015
   140
                  )
cg@2015
   141
                 (ViewSpec
cg@2015
   142
                    name: 'Box1'
cg@2015
   143
                    component: 
cg@2015
   144
                   (SpecCollection
cg@2015
   145
                      collection: (
cg@2015
   146
                       (LabelSpec
cg@2015
   147
                          label: 'Original String (Key):'
cg@2015
   148
                          name: 'Label2'
cg@2015
   149
                          layout: (LayoutFrame 0 0 0 0 0 1 30 0)
cg@2015
   150
                          translateLabel: true
cg@2015
   151
                          adjust: left
cg@2015
   152
                        )
cg@2015
   153
                       (TextEditorSpec
cg@2015
   154
                          name: 'OriginalText'
cg@2015
   155
                          layout: (LayoutFrame 0 0 30 0 0 1 0 1)
cg@2015
   156
                          model: originalTextHolder
cg@2015
   157
                          hasHorizontalScrollBar: true
cg@2015
   158
                          hasVerticalScrollBar: true
cg@2015
   159
                          modifiedChannel: originalTextModifiedHolder
cg@2015
   160
                        )
cg@2015
   161
                       )
cg@2015
   162
                     
cg@2015
   163
                    )
cg@2015
   164
                  )
cg@2015
   165
                 (ViewSpec
cg@2015
   166
                    name: 'Box2'
cg@2015
   167
                    component: 
cg@2015
   168
                   (SpecCollection
cg@2015
   169
                      collection: (
cg@2015
   170
                       (LabelSpec
cg@2015
   171
                          label: 'Translated String:'
cg@2015
   172
                          name: 'Label1'
cg@2015
   173
                          layout: (LayoutFrame 0 0 0 0 0 1 30 0)
cg@2015
   174
                          translateLabel: true
cg@2015
   175
                          adjust: left
cg@2015
   176
                        )
cg@2015
   177
                       (TextEditorSpec
cg@2015
   178
                          name: 'LanguageText'
cg@2015
   179
                          layout: (LayoutFrame 0 0 30 0 0 1 0 1)
cg@2015
   180
                          model: languageTextHolder
cg@2015
   181
                          hasHorizontalScrollBar: true
cg@2015
   182
                          hasVerticalScrollBar: true
cg@2015
   183
                          modifiedChannel: languageTextModifiedHolder
cg@2015
   184
                        )
cg@2015
   185
                       )
cg@2015
   186
                     
cg@2015
   187
                    )
cg@2015
   188
                  )
cg@2015
   189
                 )
cg@2015
   190
               
cg@2015
   191
              )
cg@2015
   192
              handles: (Any 0.33333333333333 0.66666666666667 1.0)
cg@2015
   193
            )
cg@2015
   194
           )
cg@2015
   195
         
cg@2015
   196
        )
cg@2015
   197
      )
cg@2015
   198
! !
cg@2015
   199
cg@2015
   200
!InternationalLanguageTranslationEditor class methodsFor:'menu specs'!
cg@2015
   201
cg@2015
   202
mainMenu
cg@2015
   203
    "This resource specification was automatically generated
cg@2015
   204
     by the MenuEditor of ST/X."
cg@2015
   205
cg@2015
   206
    "Do not manually edit this!! If it is corrupted,
cg@2015
   207
     the MenuEditor may not be able to read the specification."
cg@2015
   208
cg@2015
   209
    "
cg@2015
   210
     MenuEditor new openOnClass:InternationalLanguageTranslationEditor andSelector:#mainMenu
cg@2015
   211
     (Menu new fromLiteralArrayEncoding:(InternationalLanguageTranslationEditor mainMenu)) startUp
cg@2015
   212
    "
cg@2015
   213
cg@2015
   214
    <resource: #menu>
cg@2015
   215
cg@2015
   216
    ^ 
cg@2015
   217
     #(Menu
cg@2015
   218
        (
cg@2015
   219
         (MenuItem
cg@2015
   220
            label: 'File'
cg@2015
   221
            translateLabel: true
cg@2015
   222
            submenu: 
cg@2015
   223
           (Menu
cg@2015
   224
              (
cg@2015
   225
               (MenuItem
cg@2015
   226
                  label: 'New'
cg@2015
   227
                  itemValue: menuNew
cg@2015
   228
                  translateLabel: true
cg@2015
   229
                )
cg@2015
   230
               (MenuItem
cg@2015
   231
                  label: '-'
cg@2015
   232
                )
cg@2015
   233
               (MenuItem
cg@2015
   234
                  label: 'Open Resource File...'
cg@2015
   235
                  itemValue: menuOpen
cg@2015
   236
                  translateLabel: true
cg@2015
   237
                )
cg@2015
   238
               (MenuItem
cg@2015
   239
                  label: '-'
cg@2015
   240
                )
cg@2015
   241
               (MenuItem
cg@2015
   242
                  label: 'Save Resource File'
cg@2015
   243
                  itemValue: menuSave
cg@2015
   244
                  translateLabel: true
cg@2015
   245
                )
cg@2015
   246
               (MenuItem
cg@2015
   247
                  label: 'Save Resource File As...'
cg@2015
   248
                  itemValue: menuSaveAs
cg@2015
   249
                  translateLabel: true
cg@2015
   250
                )
cg@2015
   251
               (MenuItem
cg@2015
   252
                  label: '-'
cg@2015
   253
                )
cg@2015
   254
               (MenuItem
cg@2015
   255
                  label: 'Exit'
cg@2015
   256
                  itemValue: closeRequest
cg@2015
   257
                  translateLabel: true
cg@2015
   258
                )
cg@2015
   259
               )
cg@2015
   260
              nil
cg@2015
   261
              nil
cg@2015
   262
            )
cg@2015
   263
          )
cg@2015
   264
         (MenuItem
cg@2015
   265
            label: 'View'
cg@2015
   266
            translateLabel: true
cg@2015
   267
            submenu: 
cg@2015
   268
           (Menu
cg@2015
   269
              (
cg@2015
   270
               (MenuItem
cg@2015
   271
                  label: 'Show Missing Translations Only'
cg@2015
   272
                  translateLabel: true
cg@2015
   273
                  indication: showMissingTranslationsOnly
cg@2015
   274
                )
cg@2015
   275
               (MenuItem
cg@2015
   276
                  label: '-'
cg@2015
   277
                )
cg@2015
   278
               (MenuItem
cg@2015
   279
                  label: 'Shown Languages'
cg@2015
   280
                  translateLabel: true
cg@2015
   281
                  submenuChannel: shownLanguagesMenu
cg@2015
   282
                )
cg@2015
   283
               )
cg@2015
   284
              nil
cg@2015
   285
              nil
cg@2015
   286
            )
cg@2015
   287
          )
cg@2015
   288
         (MenuItem
cg@2015
   289
            label: 'Languages'
cg@2015
   290
            translateLabel: true
cg@2015
   291
            submenu: 
cg@2015
   292
           (Menu
cg@2015
   293
              (
cg@2015
   294
               (MenuItem
cg@2015
   295
                  label: 'Add Language...'
cg@2015
   296
                  itemValue: addLanguage
cg@2015
   297
                  translateLabel: true
cg@2015
   298
                )
cg@2015
   299
               (MenuItem
cg@2015
   300
                  label: 'Remove Language...'
cg@2015
   301
                  itemValue: removeLanguage
cg@2015
   302
                  translateLabel: true
cg@2015
   303
                )
cg@2015
   304
               )
cg@2015
   305
              nil
cg@2015
   306
              nil
cg@2015
   307
            )
cg@2015
   308
          )
cg@2015
   309
         (MenuItem
cg@2015
   310
            label: 'Translations'
cg@2015
   311
            translateLabel: true
cg@2015
   312
            submenu: 
cg@2015
   313
           (Menu
cg@2015
   314
              (
cg@2015
   315
               (MenuItem
cg@2015
   316
                  label: 'Add Translation...'
cg@2015
   317
                  itemValue: addTranslation
cg@2015
   318
                  translateLabel: true
cg@2015
   319
                )
cg@2015
   320
               (MenuItem
cg@2015
   321
                  label: 'Remove Translation...'
cg@2015
   322
                  itemValue: removeTranslation
cg@2015
   323
                  translateLabel: true
cg@2015
   324
                )
cg@2015
   325
               (MenuItem
cg@2015
   326
                  label: '-'
cg@2015
   327
                )
cg@2015
   328
               (MenuItem
cg@2015
   329
                  label: 'Extract from Class...'
cg@2015
   330
                  itemValue: extractTranslationsFromClass
cg@2015
   331
                  translateLabel: true
cg@2015
   332
                )
cg@2015
   333
               (MenuItem
cg@2032
   334
                  label: 'Extract from Project...'
cg@2032
   335
                  itemValue: extractTranslationsFromProject
cg@2032
   336
                  translateLabel: true
cg@2032
   337
                )
cg@2032
   338
               (MenuItem
cg@2032
   339
                  label: '-'
cg@2032
   340
                )
cg@2032
   341
               (MenuItem
cg@2015
   342
                  label: 'Run Application and Collect Translations...'
cg@2015
   343
                  itemValue: runApplicationAndCollectTranslations
cg@2015
   344
                  translateLabel: true
cg@2015
   345
                )
cg@2015
   346
               )
cg@2015
   347
              nil
cg@2015
   348
              nil
cg@2015
   349
            )
cg@2015
   350
          )
cg@2015
   351
         (MenuItem
cg@2015
   352
            label: 'Help'
cg@2015
   353
            translateLabel: true
cg@2015
   354
            startGroup: right
cg@2015
   355
            submenu: 
cg@2015
   356
           (Menu
cg@2015
   357
              (
cg@2015
   358
               (MenuItem
cg@2015
   359
                  label: 'Documentation'
cg@2015
   360
                  itemValue: openDocumentation
cg@2015
   361
                  translateLabel: true
cg@2015
   362
                )
cg@2015
   363
               (MenuItem
cg@2015
   364
                  label: '-'
cg@2015
   365
                )
cg@2015
   366
               (MenuItem
cg@2015
   367
                  label: 'About this Application...'
cg@2015
   368
                  itemValue: openAboutThisApplication
cg@2015
   369
                  translateLabel: true
cg@2015
   370
                )
cg@2015
   371
               )
cg@2015
   372
              nil
cg@2015
   373
              nil
cg@2015
   374
            )
cg@2015
   375
          )
cg@2015
   376
         )
cg@2015
   377
        nil
cg@2015
   378
        nil
cg@2015
   379
      )
cg@2015
   380
!
cg@2015
   381
cg@2015
   382
menuToolBar
cg@2015
   383
    "This resource specification was automatically generated
cg@2015
   384
     by the MenuEditor of ST/X."
cg@2015
   385
cg@2015
   386
    "Do not manually edit this!! If it is corrupted,
cg@2015
   387
     the MenuEditor may not be able to read the specification."
cg@2015
   388
cg@2015
   389
    "
cg@2015
   390
     MenuEditor new openOnClass:InternationalLanguageTranslationEditor andSelector:#menuToolBar
cg@2015
   391
     (Menu new fromLiteralArrayEncoding:(InternationalLanguageTranslationEditor menuToolBar)) startUp
cg@2015
   392
    "
cg@2015
   393
cg@2015
   394
    <resource: #menu>
cg@2015
   395
cg@2015
   396
    ^ 
cg@2015
   397
     #(Menu
cg@2015
   398
        (
cg@2015
   399
         (MenuItem
cg@2015
   400
            label: 'Save'
cg@2015
   401
            translateLabel: true
cg@2015
   402
            labelImage: (ResourceRetriever XPToolbarIconLibrary saveImageIcon)
cg@2015
   403
          )
cg@2015
   404
         (MenuItem
cg@2015
   405
            label: '-'
cg@2015
   406
          )
cg@2015
   407
         (MenuItem
cg@2015
   408
            label: 'Add Translation'
cg@2015
   409
            itemValue: addTranslation
cg@2015
   410
            translateLabel: true
cg@2015
   411
            labelImage: (ResourceRetriever XPToolbarIconLibrary newRowIcon)
cg@2015
   412
          )
cg@2015
   413
         (MenuItem
cg@2015
   414
            label: 'Remove Translation'
cg@2015
   415
            itemValue: removeTranslation
cg@2015
   416
            translateLabel: true
cg@2015
   417
            labelImage: (ResourceRetriever XPToolbarIconLibrary removeRowIcon)
cg@2015
   418
          )
cg@2015
   419
         (MenuItem
cg@2015
   420
            label: ''
cg@2015
   421
          )
cg@2015
   422
         (MenuItem
cg@2015
   423
            label: 'Stop Application'
cg@2015
   424
            itemValue: stopApplication
cg@2015
   425
            translateLabel: true
cg@2015
   426
            isVisible: stopApplicationIconVisibleHolder
cg@2015
   427
            labelImage: (ResourceRetriever XPToolbarIconLibrary stop16x16Icon)
cg@2015
   428
          )
cg@2015
   429
         )
cg@2015
   430
        nil
cg@2015
   431
        nil
cg@2015
   432
      )
cg@2015
   433
! !
cg@2015
   434
cg@2015
   435
!InternationalLanguageTranslationEditor methodsFor:'aspects'!
cg@2015
   436
cg@2015
   437
keyStringAndLanguageSelectionTable
cg@2015
   438
    keyStringsToLanguageMappings isNil ifTrue:[
cg@2015
   439
        keyStringsToLanguageMappings := KeyStringsToLanguageMappings new.
cg@2015
   440
    ].
cg@2015
   441
    ^ keyStringsToLanguageMappings.
cg@2015
   442
!
cg@2015
   443
cg@2015
   444
keyStringAndLanguageSelectionTableColumnDescriptionHolder
cg@2015
   445
    keyStringAndLanguageSelectionTableColumnDescriptionHolder isNil ifTrue:[
cg@2015
   446
        keyStringAndLanguageSelectionTableColumnDescriptionHolder := ValueHolder new.
cg@2015
   447
        keyStringAndLanguageSelectionTableColumnDescriptionHolder value:(self keyStringAndLanguageSelectionTableColumnDescription).
cg@2015
   448
    ].
cg@2015
   449
    ^ keyStringAndLanguageSelectionTableColumnDescriptionHolder.
cg@2015
   450
!
cg@2015
   451
cg@2015
   452
languageAtCol:colNr
cg@2015
   453
    ^ shownLanguages at:colNr-1.
cg@2015
   454
!
cg@2015
   455
cg@2015
   456
languageShownHolderFor:lang
cg@2015
   457
    |holder|
cg@2015
   458
cg@2015
   459
    languageShownHolders isNil ifTrue:[
cg@2015
   460
        languageShownHolders := Dictionary new
cg@2015
   461
    ].
cg@2015
   462
    holder := languageShownHolders 
cg@2015
   463
                at:lang 
cg@2015
   464
                ifAbsentPut:[ 
cg@2015
   465
                    |h|
cg@2015
   466
cg@2015
   467
                    h := true asValue.
cg@2015
   468
                    h onChangeEvaluate:[ 
cg@2015
   469
                        h value ifTrue:[
cg@2015
   470
                           self enableLanguageDisplayFor:lang     
cg@2015
   471
                        ] ifFalse:[
cg@2015
   472
                           self disableLanguageDisplayFor:lang     
cg@2015
   473
                        ].
cg@2015
   474
                    ].
cg@2015
   475
                    h
cg@2015
   476
                ].
cg@2015
   477
    ^ holder.
cg@2015
   478
!
cg@2015
   479
cg@2015
   480
languageTextHolder
cg@2015
   481
    languageTextHolder isNil ifTrue:[
cg@2015
   482
        languageTextHolder := '' asValue.
cg@2015
   483
    ].
cg@2015
   484
    ^ languageTextHolder.
cg@2015
   485
!
cg@2015
   486
cg@2015
   487
languageTextModifiedHolder
cg@2015
   488
    languageTextModifiedHolder isNil ifTrue:[
cg@2015
   489
        languageTextModifiedHolder := false asValue.
cg@2015
   490
    ].
cg@2015
   491
    ^ languageTextModifiedHolder.
cg@2015
   492
!
cg@2015
   493
cg@2015
   494
languagesList
cg@2015
   495
    languagesList isNil ifTrue:[
cg@2015
   496
        languagesList := List withAll:(self keyStringAndLanguageSelectionTable languages).
cg@2015
   497
    ].
cg@2015
   498
    ^ languagesList.
cg@2015
   499
!
cg@2015
   500
cg@2015
   501
originalTextHolder
cg@2015
   502
    originalTextHolder isNil ifTrue:[
cg@2015
   503
        originalTextHolder := '' asValue.
cg@2015
   504
    ].
cg@2015
   505
    ^ originalTextHolder.
cg@2015
   506
!
cg@2015
   507
cg@2015
   508
originalTextModifiedHolder
cg@2015
   509
    originalTextModifiedHolder isNil ifTrue:[
cg@2015
   510
        originalTextModifiedHolder := false asValue.
cg@2015
   511
    ].
cg@2015
   512
    ^ originalTextModifiedHolder.
cg@2015
   513
!
cg@2015
   514
cg@2015
   515
selectedKeyRow
cg@2015
   516
    selectedKeyRow isNil ifTrue:[
cg@2015
   517
        selectedKeyRow := ValueHolder new.
cg@2015
   518
        selectedKeyRow onChangeSend:#selectionChanged to:self.
cg@2015
   519
    ].
cg@2015
   520
    ^ selectedKeyRow.
cg@2015
   521
!
cg@2015
   522
cg@2015
   523
showMissingTranslationsOnly
cg@2015
   524
    showMissingTranslationsOnly isNil ifTrue:[
cg@2015
   525
        showMissingTranslationsOnly := false asValue.
cg@2015
   526
    ].
cg@2015
   527
    ^ showMissingTranslationsOnly.
cg@2015
   528
!
cg@2015
   529
cg@2015
   530
shownLanguages
cg@2015
   531
    shownLanguages isNil ifTrue:[
cg@2015
   532
        shownLanguages := List new.
cg@2015
   533
        shownLanguages addAll:(self languagesList).
cg@2015
   534
        shownLanguages onChangeSend:#shownLanguagesChanged to:self.
cg@2015
   535
    ].
cg@2015
   536
    ^ shownLanguages.
cg@2015
   537
!
cg@2015
   538
cg@2015
   539
stopApplicationIconVisibleHolder
cg@2015
   540
    stopApplicationIconVisibleHolder isNil ifTrue:[
cg@2015
   541
        stopApplicationIconVisibleHolder := false asValue.
cg@2015
   542
    ].
cg@2015
   543
    ^ stopApplicationIconVisibleHolder.
cg@2015
   544
! !
cg@2015
   545
cg@2015
   546
!InternationalLanguageTranslationEditor methodsFor:'initialization & release'!
cg@2015
   547
cg@2015
   548
closeRequest
cg@2015
   549
    "asks for permission before closing"
cg@2015
   550
cg@2015
   551
    self hasUnsavedChanges ifTrue:[
cg@2015
   552
        (Dialog 
cg@2015
   553
            confirm:(resources string:'Close without saving ?')
cg@2015
   554
            default:false) ifFalse:[
cg@2015
   555
            ^ self
cg@2015
   556
        ]
cg@2015
   557
    ].
cg@2015
   558
cg@2015
   559
    super closeRequest
cg@2015
   560
!
cg@2015
   561
cg@2015
   562
initialize
cg@2015
   563
    modified := false.
cg@2031
   564
    inSingleFileMode := false.
cg@2015
   565
    super initialize
cg@2015
   566
!
cg@2015
   567
cg@2015
   568
postBuildDataSet:aView
cg@2015
   569
    dataSetView := aView
cg@2015
   570
! !
cg@2015
   571
cg@2015
   572
!InternationalLanguageTranslationEditor methodsFor:'menu actions'!
cg@2015
   573
cg@2015
   574
addLanguage
cg@2015
   575
    |lang|
cg@2015
   576
cg@2015
   577
    lang := Dialog request:'New language (ISO symbol):'.
cg@2015
   578
    lang isEmptyOrNil ifTrue:[^ self].
cg@2015
   579
cg@2015
   580
    (keyStringsToLanguageMappings includesLanguage:lang) ifTrue:[^ self ].
cg@2015
   581
cg@2015
   582
    keyStringsToLanguageMappings addLanguage:lang.
cg@2015
   583
    self languagesList add:lang.
cg@2015
   584
    self shownLanguages add:lang.
cg@2015
   585
    modified := true.
cg@2015
   586
!
cg@2015
   587
cg@2015
   588
addTranslation
cg@2015
   589
    |key index|
cg@2015
   590
cg@2015
   591
    key := Dialog request:'New Key:'.
cg@2015
   592
    (keyStringsToLanguageMappings includesKey:key) ifFalse:[
cg@2015
   593
        keyStringsToLanguageMappings addKey:key.
cg@2015
   594
        modified := true.
cg@2015
   595
    ].
cg@2015
   596
    index := keyStringsToLanguageMappings indexOfKey:key.
cg@2015
   597
cg@2015
   598
    self selectedKeyRow value:index
cg@2015
   599
!
cg@2015
   600
cg@2015
   601
extractTranslationsFromClass
cg@2015
   602
    |aClass newTranslations|
cg@2015
   603
cg@2015
   604
    aClass := Dialog 
cg@2015
   605
                requestClass:'Class to extract translations from:'
cg@2015
   606
                okLabel:'OK' 
cg@2015
   607
                initialAnswer:(lastExtractedClass ? LastExtractedClass).
cg@2015
   608
    aClass isNil ifTrue:[^ self ].
cg@2015
   609
cg@2015
   610
    lastExtractedClass := LastExtractedClass := aClass.
cg@2015
   611
cg@2032
   612
    newTranslations := self extractTranslationsFromClass:aClass.
cg@2032
   613
    self addAllTranslations:newTranslations.
cg@2032
   614
!
cg@2032
   615
cg@2032
   616
extractTranslationsFromProject
cg@2032
   617
    |box projectID newTranslations|
cg@2032
   618
cg@2032
   619
    box := ListSelectionBox new.
cg@2032
   620
"/    box useComboBoxWithList:(Smalltalk allProjectIDs).
cg@2032
   621
    box title:(resources string:'Project to extract translations from:').
cg@2032
   622
    box list:Smalltalk allProjectIDs.
cg@2032
   623
    box okAction:[:sel | projectID := sel].
cg@2032
   624
    box initialText:(lastExtractedProject ? LastExtractedProject).
cg@2032
   625
    box label:'Find Translations in Project'.
cg@2032
   626
cg@2032
   627
    box showAtPointer.
cg@2032
   628
cg@2032
   629
    projectID notNil ifTrue:[
cg@2032
   630
        projectID := projectID withoutSeparators asSymbol.
cg@2032
   631
    ].
cg@2032
   632
    projectID isEmptyOrNil ifTrue:[^ self ].
cg@2032
   633
cg@2032
   634
    lastExtractedProject := LastExtractedProject := projectID.
cg@2032
   635
cg@2015
   636
    newTranslations := Set new.
cg@2015
   637
cg@2032
   638
    Smalltalk allClassesDo:[:eachClass |
cg@2032
   639
        eachClass theNonMetaclass package == projectID ifTrue:[
cg@2032
   640
"/ eachClass isLoaded ifTrue:[ self halt. ].
cg@2032
   641
            newTranslations addAll:( self extractTranslationsFromClass:eachClass theNonMetaclass).
cg@2032
   642
        ]
cg@2015
   643
    ].
cg@2015
   644
cg@2032
   645
    self addAllTranslations:newTranslations.
cg@2015
   646
!
cg@2015
   647
cg@2015
   648
menuNew
cg@2015
   649
    modified ifTrue:[
cg@2015
   650
        (Dialog 
cg@2015
   651
            confirm:(resources stringWithCRs:'Modified translations have not been changed.\\Create new translations set anyway ?')
cg@2015
   652
            default:false) ifFalse:[^ self].
cg@2015
   653
    ].
cg@2015
   654
cg@2015
   655
    keyStringsToLanguageMappings initialize.
cg@2015
   656
    keyStringsToLanguageMappings changed.
cg@2015
   657
cg@2015
   658
    self languagesList contents:self keyStringAndLanguageSelectionTable languages.
cg@2015
   659
    self shownLanguages contents:self keyStringAndLanguageSelectionTable languages.
cg@2015
   660
    modified := false.
cg@2015
   661
!
cg@2015
   662
cg@2015
   663
menuOpen
cg@2015
   664
    |fn|
cg@2015
   665
cg@2015
   666
    fn := Dialog 
cg@2015
   667
        requestFileName:'Name of resource file:'
cg@2015
   668
        default:nil 
cg@2015
   669
        pattern:'*.rs'.
cg@2015
   670
cg@2015
   671
    fn isEmptyOrNil ifTrue:[^ self ].
cg@2015
   672
    fn := fn asFilename.
cg@2015
   673
    fn exists ifFalse:[^ self ].
cg@2015
   674
cg@2015
   675
    self readResourceFile:fn
cg@2015
   676
!
cg@2015
   677
cg@2015
   678
menuSave
cg@2015
   679
    "This method was generated by the Browser.
cg@2015
   680
     It will be invoked when the menu-item 'save' is selected."
cg@2015
   681
cg@2015
   682
    "/ change below and add any actions as required here ...
cg@2015
   683
    self warn:'no action for ''save'' available.'.
cg@2015
   684
!
cg@2015
   685
cg@2015
   686
menuSaveAs
cg@2015
   687
    "This method was generated by the Browser.
cg@2015
   688
     It will be invoked when the menu-item 'saveAs' is selected."
cg@2015
   689
cg@2015
   690
    "/ change below and add any actions as required here ...
cg@2015
   691
    self warn:'no action for ''saveAs'' available.'.
cg@2015
   692
!
cg@2015
   693
cg@2015
   694
openAboutThisApplication
cg@2015
   695
    "This method was generated by the Browser.
cg@2015
   696
     It will be invoked when the menu-item 'help-about' is selected."
cg@2015
   697
cg@2015
   698
    "/ could open a customized aboutBox here ...
cg@2015
   699
    super openAboutThisApplication
cg@2015
   700
!
cg@2015
   701
cg@2015
   702
openDocumentation
cg@2015
   703
    "This method was generated by the Browser.
cg@2015
   704
     It will be invoked when the menu-item 'help-documentation' is selected."
cg@2015
   705
cg@2015
   706
    "/ change below as required ...
cg@2015
   707
cg@2015
   708
    "/ to open an HTML viewer on some document (under 'doc/online/<language>/' ):
cg@2015
   709
    HTMLDocumentView openFullOnDocumentationFile:'TOP.html'.
cg@2015
   710
cg@2015
   711
    "/ add application-specific help files under the 'doc/online/<language>/help/appName'
cg@2015
   712
    "/ directory, and open a viewer with:
cg@2015
   713
    "/ HTMLDocumentView openFullOnDocumentationFile:'help/<MyApplication>/TOP.html'.
cg@2015
   714
!
cg@2015
   715
cg@2015
   716
readResourceFile:aFilename
cg@2031
   717
    |lang|
cg@2031
   718
cg@2031
   719
    lang := Dialog choose:'For which language ?' fromList:languagesList lines:10.
cg@2031
   720
    lang isNil ifTrue:[^ self ].
cg@2031
   721
cg@2031
   722
    self readResourceFile:aFilename asLanguage:lang asSymbol
cg@2031
   723
!
cg@2031
   724
cg@2031
   725
readResourceFile:aFilename asLanguage:lang
cg@2031
   726
    |resourcePack inStream lineString encoding decoder sortedKeys remainingKeys|
cg@2015
   727
cg@2015
   728
    aFilename exists ifFalse:[^ self ].
cg@2015
   729
cg@2031
   730
    resourcePack := ResourcePack new.
cg@2031
   731
cg@2015
   732
    inStream := aFilename readStream.
cg@2015
   733
    [inStream atEnd] whileFalse:[
cg@2015
   734
        lineString := inStream nextLine.
cg@2015
   735
        (lineString notEmpty 
cg@2015
   736
        and:[ (lineString startsWith:';') not ]) ifTrue:[
cg@2031
   737
            ((lineString startsWith:'#') and:[(lineString startsWith:'#(') not]) ifTrue:[
cg@2031
   738
                lineString := (lineString copyFrom:2) withoutSeparators.
cg@2031
   739
                (lineString startsWith:'encoding ') ifTrue:[
cg@2031
   740
                    encoding := ResourcePack extractEncodingFromLine:lineString.
cg@2031
   741
                    decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil.
cg@2031
   742
                ].
cg@2015
   743
            ] ifFalse:[
cg@2031
   744
                ResourcePack
cg@2031
   745
                    processResourceLine:lineString 
cg@2031
   746
                    encoding:decoder 
cg@2031
   747
                    file:aFilename pathName 
cg@2031
   748
                    printErrorWith:[:msg | Transcript showCR:msg ] 
cg@2031
   749
                    for:resourcePack
cg@2031
   750
                    keepUselessTranslations:true.
cg@2015
   751
            ].
cg@2015
   752
        ].
cg@2015
   753
    ].
cg@2015
   754
    inStream close.
cg@2031
   755
cg@2031
   756
    sortedKeys := (resourcePack keys select:[:k | k isString]) asSortedCollection.
cg@2031
   757
    remainingKeys := resourcePack keys select:[:k | k isString not].
cg@2031
   758
cg@2031
   759
    sortedKeys do:[:k |
cg@2031
   760
        keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k)
cg@2031
   761
    ].
cg@2031
   762
    remainingKeys do:[:k |
cg@2031
   763
        keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k)
cg@2031
   764
    ].
cg@2015
   765
!
cg@2015
   766
cg@2015
   767
removeLanguage
cg@2015
   768
    "automatically generated by UIEditor ..."
cg@2015
   769
cg@2015
   770
    "*** the code below performs no action"
cg@2015
   771
    "*** (except for some feedback on the Transcript)"
cg@2015
   772
    "*** Please change as required and accept in the browser."
cg@2015
   773
    "*** (and replace this comment by something more useful ;-)"
cg@2015
   774
cg@2015
   775
    "action to be added ..."
cg@2015
   776
cg@2015
   777
    Transcript showCR:self class name, ': action for #removeLanguage ...'.
cg@2015
   778
!
cg@2015
   779
cg@2015
   780
removeTranslation
cg@2015
   781
    |rowSelectionIndex selectedKey|
cg@2015
   782
cg@2015
   783
    rowSelectionIndex := self selectedKeyRow value.
cg@2015
   784
    rowSelectionIndex ~~ 0 ifTrue:[
cg@2015
   785
        selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex ifAbsent:nil.
cg@2015
   786
        (Dialog confirm:(resources string:'Really remove key %1' with:selectedKey)) ifTrue:[
cg@2015
   787
            keyStringsToLanguageMappings removeKey:selectedKey.
cg@2015
   788
        ].
cg@2015
   789
    ].
cg@2015
   790
!
cg@2015
   791
cg@2015
   792
runApplicationAndCollectTranslations
cg@2015
   793
    |applicationClass newTranslations pseudoPack app|
cg@2015
   794
cg@2015
   795
    monitoredApplication notNil ifTrue:[
cg@2015
   796
        monitoredApplication terminate.
cg@2015
   797
        [monitoredApplication notNil] whileTrue:[
cg@2015
   798
            Delay waitForSeconds:0.1
cg@2015
   799
        ].
cg@2015
   800
    ].
cg@2015
   801
cg@2015
   802
    applicationClass := Dialog 
cg@2015
   803
                requestClass:'Application class to start and collect translations from:'
cg@2015
   804
                okLabel:'OK' 
cg@2015
   805
                initialAnswer:(lastExtractedApplicationClass ? LastExtractedApplicationClass ).
cg@2015
   806
    applicationClass isNil ifTrue:[^ self ].
cg@2015
   807
cg@2015
   808
    lastExtractedApplicationClass := LastExtractedApplicationClass := applicationClass.
cg@2015
   809
cg@2015
   810
    newTranslations := Set new.
cg@2015
   811
cg@2015
   812
    pseudoPack := AccessCollectingPseudoResourcePack new.
cg@2015
   813
    pseudoPack realResourcePack:(applicationClass classResources).
cg@2015
   814
cg@2015
   815
    self stopApplicationIconVisibleHolder value:true.
cg@2015
   816
cg@2015
   817
    monitoredApplication := [
cg@2015
   818
        [
cg@2015
   819
            app := applicationClass new.
cg@2015
   820
            app open.
cg@2015
   821
            app window waitUntilVisible.
cg@2015
   822
            app window waitUntilClosed.
cg@2015
   823
        ] ensure:[
cg@2015
   824
            app closeRequest.
cg@2015
   825
            self stopApplicationIconVisibleHolder value:false.
cg@2015
   826
            monitoredApplication := nil.
cg@2015
   827
        ].
cg@2015
   828
    ] fork.
cg@2015
   829
! !
cg@2015
   830
cg@2015
   831
!InternationalLanguageTranslationEditor methodsFor:'menus dynamic'!
cg@2015
   832
cg@2015
   833
disableLanguageDisplayFor:lang
cg@2015
   834
    self shownLanguages remove:lang ifAbsent:[]
cg@2015
   835
!
cg@2015
   836
cg@2015
   837
enableLanguageDisplayFor:newLang
cg@2015
   838
    |shownLanguagesInOrder|
cg@2015
   839
cg@2015
   840
    (self shownLanguages includes:newLang) ifFalse:[
cg@2015
   841
        shownLanguagesInOrder := self languagesList
cg@2015
   842
                                    select:[:lang | (self shownLanguages includes:lang)
cg@2015
   843
                                                    or:[ lang = newLang ]].
cg@2015
   844
        self shownLanguages contents:shownLanguagesInOrder.
cg@2015
   845
    ]
cg@2015
   846
!
cg@2015
   847
cg@2015
   848
isLanguageShown:lang
cg@2015
   849
    ^ self shownLanguages includes:lang
cg@2015
   850
!
cg@2015
   851
cg@2015
   852
shownLanguagesMenu
cg@2015
   853
    <resource: #programMenu >
cg@2015
   854
cg@2015
   855
    ^ [
cg@2015
   856
        |m selected|
cg@2015
   857
cg@2015
   858
        m := Menu new.
cg@2015
   859
cg@2015
   860
        self languagesList do:[:lang |
cg@2015
   861
            |item|
cg@2015
   862
cg@2015
   863
            item := MenuItem label:lang.
cg@2015
   864
            item indication:(self languageShownHolderFor:lang).
cg@2015
   865
            item hideMenuOnActivated:false.    
cg@2015
   866
            m addItem:item.
cg@2015
   867
        ].
cg@2015
   868
        m
cg@2015
   869
    ].
cg@2015
   870
!
cg@2015
   871
cg@2015
   872
toggleLanguageDisplayFor:lang
cg@2015
   873
    (self shownLanguages includes:lang) ifTrue:[
cg@2015
   874
        self disableLanguageDisplayFor:lang
cg@2015
   875
    ] ifFalse:[
cg@2015
   876
        self enableLanguageDisplayFor:lang
cg@2015
   877
    ].
cg@2015
   878
! !
cg@2015
   879
cg@2015
   880
!InternationalLanguageTranslationEditor methodsFor:'private-key extraction'!
cg@2015
   881
cg@2032
   882
addAllTranslations:newTranslations
cg@2034
   883
    |newTranslationKeys stringKeys nonStringKeys|
cg@2032
   884
cg@2034
   885
    newTranslationKeys := newTranslations select:[:k | k notEmpty and:[k isString not or:[k isBlank not]]].
cg@2032
   886
    newTranslationKeys := newTranslationKeys select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
cg@2034
   887
    newTranslationKeys := newTranslationKeys 
cg@2034
   888
                                collect:[:k | 
cg@2034
   889
                                        (k endsWith:'...') ifTrue:[
cg@2034
   890
                                            k copyWithoutLast:3.
cg@2034
   891
                                        ] ifFalse:[
cg@2034
   892
                                            ('.:' includes:k last) ifTrue:[
cg@2034
   893
                                                k copyWithoutLast:1.
cg@2034
   894
                                            ] ifFalse:[
cg@2034
   895
                                                k
cg@2034
   896
                                        ]]].
cg@2034
   897
    newTranslationKeys := newTranslationKeys asSet.
cg@2034
   898
cg@2032
   899
    newTranslationKeys notEmpty ifTrue:[
cg@2034
   900
        stringKeys := newTranslationKeys select:[:k | k isString].
cg@2034
   901
        nonStringKeys := newTranslationKeys select:[:k | k isString not].
cg@2034
   902
cg@2034
   903
        stringKeys := stringKeys asSortedCollection.
cg@2034
   904
        keyStringsToLanguageMappings addKeys:stringKeys.
cg@2034
   905
        keyStringsToLanguageMappings addKeys:nonStringKeys.
cg@2032
   906
        modified := true.
cg@2032
   907
    ].
cg@2032
   908
!
cg@2032
   909
cg@2032
   910
extractTranslationsFromClass:aClass
cg@2032
   911
    |newTranslations|
cg@2032
   912
cg@2032
   913
    newTranslations := Set new.
cg@2032
   914
cg@2032
   915
    self withWaitCursorDo:[
cg@2032
   916
        "/ now, the hard part:
cg@2032
   917
        "/ possible translations are in the specs,
cg@2032
   918
        "/ and all arguments to (resources string:) messages.
cg@2032
   919
        aClass instAndClassMethodsDo:[:eachMethod |
cg@2032
   920
            newTranslations addAll:( self extractTranslationsFromMethod:eachMethod ).
cg@2032
   921
        ].
cg@2032
   922
    ].
cg@2032
   923
    ^ newTranslations
cg@2032
   924
!
cg@2032
   925
cg@2015
   926
extractTranslationsFromHelpSpecMethod:aMethod
cg@2015
   927
    |codeStrings matcher parseTree resourceKeys|
cg@2015
   928
cg@2015
   929
    parseTree := RBParser 
cg@2015
   930
            parseMethod:aMethod source 
cg@2015
   931
            onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
cg@2015
   932
                                  nil].
cg@2015
   933
    parseTree isNil ifTrue:[^ #() ].
cg@2015
   934
cg@2015
   935
    codeStrings  := 
cg@2015
   936
        #(
cg@2015
   937
                '`@dict addPairsFrom: `#helpKeysAndStrings'
cg@2015
   938
        ).
cg@2015
   939
cg@2015
   940
    resourceKeys := Set new.
cg@2015
   941
cg@2015
   942
    matcher := ParseTreeSearcher new.
cg@2015
   943
    matcher 
cg@2015
   944
        matchesAnyOf: codeStrings 
cg@2015
   945
        do: [:aNode :answer |
cg@2015
   946
                |sel argNode arg|
cg@2015
   947
cg@2015
   948
                sel := aNode selector.
cg@2015
   949
                (sel startsWith:'addPairsFrom:') ifTrue:[
cg@2015
   950
                    argNode := aNode arguments at:1.
cg@2015
   951
                    argNode isLiteral ifTrue:[
cg@2015
   952
                        arg := argNode value.
cg@2015
   953
                        arg isArray ifTrue:[
cg@2015
   954
                            arg doWithIndex:[:el :index |
cg@2015
   955
                                index even ifTrue:[
cg@2015
   956
                                    el isString ifTrue:[    
cg@2015
   957
                                        resourceKeys add:el.
cg@2015
   958
                                    ]
cg@2015
   959
                                ].
cg@2015
   960
                            ].
cg@2015
   961
                        ] ifFalse:[
cg@2015
   962
                            Transcript 
cg@2015
   963
                                showCR:(resources 
cg@2015
   964
                                        string:'Cannot derive resourceKey from non-array in %1 in %2'
cg@2015
   965
                                        with:argNode formattedCode
cg@2015
   966
                                        with:aMethod selector).
cg@2015
   967
                        ].
cg@2015
   968
                    ] ifFalse:[
cg@2015
   969
                        Transcript 
cg@2015
   970
                            showCR:(resources 
cg@2015
   971
                                        string:'Cannot derive resourceKey from non-literal: %1 in %2'
cg@2015
   972
                                        with:argNode formattedCode
cg@2015
   973
                                        with:aMethod selector).
cg@2015
   974
                    ].
cg@2015
   975
                ].
cg@2015
   976
                aNode
cg@2015
   977
            ].
cg@2015
   978
cg@2015
   979
    matcher executeTree: parseTree initialAnswer: nil.
cg@2015
   980
    ^ resourceKeys
cg@2015
   981
!
cg@2015
   982
cg@2015
   983
extractTranslationsFromMenuSpecMethod:aMethod
cg@2015
   984
    |menu resourceKeys|
cg@2015
   985
cg@2015
   986
    menu := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
   987
    menu isNil ifTrue:[ ^ #() ].
cg@2015
   988
cg@2015
   989
    (menu isKindOf:Menu) ifFalse:[
cg@2015
   990
        menu := Menu new fromLiteralArrayEncoding:menu
cg@2015
   991
    ].
cg@2015
   992
cg@2015
   993
    resourceKeys := Set new.
cg@2015
   994
    menu allItemsDo:[:aMenuItem |
cg@2015
   995
        aMenuItem translateLabel ifTrue:[
cg@2015
   996
            aMenuItem isSeparatorItem ifFalse:[
cg@2015
   997
                resourceKeys add:aMenuItem label.
cg@2015
   998
            ]
cg@2015
   999
        ]
cg@2015
  1000
    ].
cg@2015
  1001
    ^ resourceKeys
cg@2015
  1002
!
cg@2015
  1003
cg@2015
  1004
extractTranslationsFromMethod:aMethod
cg@2015
  1005
    |mResources|
cg@2015
  1006
cg@2015
  1007
    mResources := aMethod resources.
cg@2015
  1008
    mResources notNil ifTrue:[
cg@2015
  1009
        (mResources includesKey:#menu) ifTrue:[
cg@2015
  1010
             ^ self extractTranslationsFromMenuSpecMethod:aMethod.
cg@2015
  1011
        ].
cg@2015
  1012
        (mResources includesKey:#canvas) ifTrue:[
cg@2015
  1013
             ^ self extractTranslationsFromUISpecMethod:aMethod.
cg@2015
  1014
        ].
cg@2015
  1015
        (mResources includesKey:#help) ifTrue:[
cg@2015
  1016
             ^ self extractTranslationsFromHelpSpecMethod:aMethod.
cg@2015
  1017
        ].
cg@2015
  1018
        (mResources includesKey:#tableColumns) ifTrue:[
cg@2015
  1019
             ^ self extractTranslationsFromTableColumnsSpecMethod:aMethod.
cg@2015
  1020
        ].
cg@2015
  1021
cg@2015
  1022
        ^ self extractTranslationsFromSpecMethod:aMethod.
cg@2015
  1023
    ].
cg@2015
  1024
    ^ self extractTranslationsFromMethodsCode:aMethod
cg@2015
  1025
!
cg@2015
  1026
cg@2015
  1027
extractTranslationsFromMethodsCode:aMethod
cg@2015
  1028
"/method:mthd selector:sel inClass:cls matchesParseTreeMatcher:aMatcher
cg@2015
  1029
    |codeStrings matcher parseTree resourceKeys|
cg@2015
  1030
cg@2015
  1031
    parseTree := RBParser 
cg@2015
  1032
            parseMethod:aMethod source 
cg@2015
  1033
            onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
cg@2015
  1034
                                  nil].
cg@2015
  1035
    parseTree isNil ifTrue:[^ #() ].
cg@2015
  1036
cg@2015
  1037
    codeStrings  := 
cg@2015
  1038
        #(
cg@2015
  1039
                'resources `@msg: `@args'
cg@2015
  1040
                'self resources `@msg: `@args'
cg@2015
  1041
                'self class resources `@msg: `@args'
cg@2015
  1042
                'self classResources `@msg: `@args'
cg@2015
  1043
        ).
cg@2015
  1044
cg@2015
  1045
    resourceKeys := Set new.
cg@2015
  1046
cg@2015
  1047
    matcher := ParseTreeSearcher new.
cg@2015
  1048
    matcher 
cg@2015
  1049
        matchesAnyOf: codeStrings 
cg@2015
  1050
        do: [:aNode :answer |
cg@2015
  1051
                |sel keyStringArgNode keyStringArg|
cg@2015
  1052
cg@2015
  1053
                sel := aNode selector.
cg@2015
  1054
                ((sel startsWith:'string:') or:[(sel startsWith:'at:')]) ifTrue:[
cg@2015
  1055
                    keyStringArgNode := aNode arguments at:1.
cg@2015
  1056
                    keyStringArgNode isLiteral ifTrue:[
cg@2015
  1057
                        keyStringArg := keyStringArgNode value.
cg@2015
  1058
                        keyStringArg isString ifTrue:[
cg@2015
  1059
                            resourceKeys add:keyStringArg.
cg@2015
  1060
                        ] ifFalse:[
cg@2015
  1061
                            Transcript 
cg@2015
  1062
                                showCR:(resources 
cg@2015
  1063
                                        string:'Cannot derive resourceKey from non-string: %1 in %2'
cg@2015
  1064
                                        with:keyStringArgNode formattedCode
cg@2015
  1065
                                        with:aMethod selector).
cg@2015
  1066
                        ].
cg@2015
  1067
                    ] ifFalse:[
cg@2015
  1068
                        Transcript 
cg@2015
  1069
                            showCR:(resources 
cg@2015
  1070
                                        string:'Cannot derive resourceKey from non-literal: %1 in %2'
cg@2015
  1071
                                        with:keyStringArgNode formattedCode
cg@2015
  1072
                                        with:aMethod selector).
cg@2015
  1073
                    ].
cg@2015
  1074
                ].
cg@2015
  1075
                aNode
cg@2015
  1076
            ].
cg@2015
  1077
cg@2015
  1078
    matcher executeTree: parseTree initialAnswer: nil.
cg@2015
  1079
    ^ resourceKeys
cg@2015
  1080
!
cg@2015
  1081
cg@2015
  1082
extractTranslationsFromSpecMethod:aMethod
cg@2015
  1083
    ^ #()
cg@2015
  1084
!
cg@2015
  1085
cg@2015
  1086
extractTranslationsFromTableColumnsSpecMethod:aMethod
cg@2015
  1087
    |columnDescription resourceKeys|
cg@2015
  1088
cg@2015
  1089
    columnDescription := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
  1090
    columnDescription isNil ifTrue:[ ^ #() ].
cg@2015
  1091
cg@2015
  1092
    (columnDescription first isKindOf:DataSetColumnSpec) ifFalse:[
cg@2015
  1093
        columnDescription := columnDescription collect:[:el | DataSetColumnSpec new fromLiteralArrayEncoding:el].
cg@2015
  1094
    ].
cg@2015
  1095
cg@2015
  1096
    resourceKeys := Set new.
cg@2015
  1097
    columnDescription do:[:aColumnSpec |
cg@2015
  1098
        aColumnSpec translateLabel ifTrue:[
cg@2015
  1099
            resourceKeys add:aColumnSpec label.
cg@2015
  1100
        ]
cg@2015
  1101
    ].
cg@2015
  1102
    ^ resourceKeys
cg@2015
  1103
!
cg@2015
  1104
cg@2015
  1105
extractTranslationsFromUISpecMethod:aMethod
cg@2015
  1106
    |spec resourceKeys visitor|
cg@2015
  1107
cg@2015
  1108
    spec := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
  1109
    spec isNil ifTrue:[ ^ #() ].
cg@2015
  1110
cg@2015
  1111
    (spec isKindOf:UISpecification) ifFalse:[
cg@2015
  1112
        spec := UISpecification from:spec
cg@2015
  1113
    ].
cg@2015
  1114
cg@2015
  1115
    resourceKeys := Set new.
cg@2015
  1116
cg@2015
  1117
    visitor := UISpecVisitor new.
cg@2015
  1118
    spec acceptVisitor:visitor.
cg@2015
  1119
cg@2015
  1120
    ^ visitor translatedLabels
cg@2015
  1121
! !
cg@2015
  1122
cg@2015
  1123
!InternationalLanguageTranslationEditor methodsFor:'queries'!
cg@2015
  1124
cg@2015
  1125
hasUnsavedChanges
cg@2015
  1126
    ^ modified
cg@2015
  1127
! !
cg@2015
  1128
cg@2015
  1129
!InternationalLanguageTranslationEditor methodsFor:'specs-dynamic'!
cg@2015
  1130
cg@2015
  1131
columnInRow:row at:colIndex
cg@2015
  1132
    |lang|
cg@2015
  1133
cg@2015
  1134
    lang := self languageAtCol:colIndex.
cg@2015
  1135
    ^ row atLanguage:lang
cg@2015
  1136
!
cg@2015
  1137
cg@2015
  1138
getBackgroundForRow:row rowNr:rowNr col:colIndex
cg@2015
  1139
    |lang|
cg@2015
  1140
cg@2015
  1141
    colIndex == 1 ifTrue:[^ nil].
cg@2015
  1142
    lang := self languageAtCol:colIndex.
cg@2015
  1143
    ^ (row atLanguage:lang) isNil ifTrue:[Color red lightened] ifFalse:nil
cg@2015
  1144
!
cg@2015
  1145
cg@2015
  1146
keyStringAndLanguageSelectionTableColumnDescription
cg@2015
  1147
    |spec|
cg@2015
  1148
cg@2015
  1149
    spec := OrderedCollection new.
cg@2015
  1150
cg@2015
  1151
    spec add:
cg@2015
  1152
      #(DataSetColumnSpec
cg@2015
  1153
         label: 'Key'
cg@2015
  1154
         labelAlignment: center
cg@2015
  1155
         labelButtonType: Button
cg@2015
  1156
         minWidth: 50
cg@2015
  1157
         model: keyStringInRow:
cg@2015
  1158
         isResizeable: true
cg@2015
  1159
         canSelect: true
cg@2015
  1160
         showRowSeparator: true
cg@2015
  1161
         showColSeparator: true
cg@2015
  1162
       ).
cg@2015
  1163
cg@2015
  1164
    self shownLanguages do:[:lang |
cg@2015
  1165
        |entry|
cg@2015
  1166
cg@2015
  1167
        entry :=
cg@2015
  1168
              #(DataSetColumnSpec
cg@2015
  1169
                 label: lang
cg@2015
  1170
                 labelAlignment: center
cg@2015
  1171
                 labelButtonType: Button
cg@2015
  1172
                 minWidth: 50
cg@2015
  1173
                 model: #columnInRow:at:
cg@2015
  1174
                 canSelect: true
cg@2015
  1175
                 isResizeable: true
cg@2015
  1176
                 showRowSeparator: true
cg@2015
  1177
                 showColSeparator: true
cg@2015
  1178
                 backgroundSelector: #getBackgroundForRow:rowNr:col:
cg@2015
  1179
               ).
cg@2015
  1180
        entry := entry copy.
cg@2015
  1181
        entry replaceAll:#lang with:lang.
cg@2015
  1182
        spec add: entry 
cg@2015
  1183
    ].
cg@2015
  1184
    ^ spec
cg@2015
  1185
!
cg@2015
  1186
cg@2015
  1187
keyStringInRow:row
cg@2015
  1188
    ^ row keyString
cg@2015
  1189
! !
cg@2015
  1190
cg@2015
  1191
!InternationalLanguageTranslationEditor methodsFor:'user actions'!
cg@2015
  1192
cg@2015
  1193
selectionChanged
cg@2015
  1194
    |rowSelectionIndex colSelectionIndex language selectedKey originalText languageText
cg@2015
  1195
     answer|
cg@2015
  1196
cg@2015
  1197
    colSelectionIndex := dataSetView selectedColIndex.
cg@2015
  1198
    language := colSelectionIndex > 1 ifTrue:[ shownLanguages at:colSelectionIndex-1 ] ifFalse:nil.
cg@2015
  1199
cg@2015
  1200
    rowSelectionIndex := self selectedKeyRow value.
cg@2015
  1201
    rowSelectionIndex ~~ 0 ifTrue:[
cg@2015
  1202
        selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex.
cg@2015
  1203
        originalText := selectedKey storeString.
cg@2015
  1204
        language notNil ifTrue:[
cg@2015
  1205
            languageText := keyStringsToLanguageMappings at:selectedKey language:language.
cg@2015
  1206
            languageText notNil ifTrue:[
cg@2015
  1207
                languageText := languageText storeString.
cg@2015
  1208
            ]
cg@2015
  1209
        ]
cg@2015
  1210
    ].
cg@2015
  1211
cg@2015
  1212
    self originalTextModifiedHolder value ifTrue:[ 
cg@2015
  1213
        answer := OptionBox 
cg@2015
  1214
                      request:'Accept changed original text (key) ?' 
cg@2015
  1215
                      label:'Original text (key) changed'
cg@2015
  1216
                      image:(WarningBox iconBitmap)
cg@2015
  1217
                      buttonLabels:#('Cancel' 'Accept' 'Accept As New')
cg@2015
  1218
                      values:#(nil #accept #acceptAsNew)
cg@2015
  1219
                      default:#acceptAsNew.
cg@2015
  1220
cg@2015
  1221
        answer isNil ifTrue:[^ self ].
cg@2015
  1222
        answer == #accept ifTrue:[
cg@2015
  1223
self halt.        ].
cg@2015
  1224
        answer == #acceptAsNew ifTrue:[
cg@2015
  1225
self halt.        ].
cg@2015
  1226
    ].
cg@2015
  1227
    self languageTextModifiedHolder value ifTrue:[ self halt.
cg@2015
  1228
        (Dialog confirm:'Accept changed translation ?') ifTrue:[
cg@2015
  1229
            self halt.
cg@2015
  1230
        ]
cg@2015
  1231
    ].
cg@2015
  1232
cg@2015
  1233
    self originalTextHolder value:originalText.
cg@2015
  1234
    self languageTextHolder value:languageText.
cg@2015
  1235
cg@2015
  1236
    self originalTextModifiedHolder value:false.
cg@2015
  1237
    self languageTextModifiedHolder value:false.
cg@2015
  1238
!
cg@2015
  1239
cg@2015
  1240
shownLanguagesChanged
cg@2015
  1241
    self keyStringAndLanguageSelectionTableColumnDescriptionHolder 
cg@2015
  1242
        value:(self keyStringAndLanguageSelectionTableColumnDescription).
cg@2015
  1243
!
cg@2015
  1244
cg@2015
  1245
stopApplication
cg@2015
  1246
    |p|
cg@2015
  1247
cg@2015
  1248
    (p := monitoredApplication) notNil ifTrue:[
cg@2015
  1249
        p terminate.
cg@2015
  1250
    ].
cg@2015
  1251
! !
cg@2015
  1252
cg@2015
  1253
!InternationalLanguageTranslationEditor::AccessCollectingPseudoResourcePack methodsFor:'accessing'!
cg@2015
  1254
cg@2015
  1255
realResourcePack:something
cg@2015
  1256
    realResourcePack := something.
cg@2015
  1257
! !
cg@2015
  1258
cg@2015
  1259
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings class methodsFor:'instance creation'!
cg@2015
  1260
cg@2015
  1261
new
cg@2015
  1262
    ^ self basicNew initialize
cg@2015
  1263
! !
cg@2015
  1264
cg@2015
  1265
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'accessing'!
cg@2015
  1266
cg@2015
  1267
addKey:aKey
cg@2031
  1268
    (keys includes:aKey) ifFalse:[
cg@2031
  1269
        keys add:aKey.
cg@2031
  1270
        self changed.
cg@2031
  1271
    ]
cg@2015
  1272
!
cg@2015
  1273
cg@2015
  1274
addKeys:aCollectionOfKey
cg@2015
  1275
    keys addAll:aCollectionOfKey.
cg@2015
  1276
    self changed.
cg@2015
  1277
!
cg@2015
  1278
cg@2015
  1279
addLanguage:lang
cg@2031
  1280
    (languages includes:lang) ifFalse:[
cg@2031
  1281
        languages add:lang.
cg@2032
  1282
        perLanguageMappings at:lang put:(Dictionary new).
cg@2031
  1283
    ]
cg@2015
  1284
!
cg@2015
  1285
cg@2015
  1286
at:aKey language:language
cg@2032
  1287
    ^ (perLanguageMappings at:language) at:aKey ifAbsent:nil
cg@2015
  1288
!
cg@2015
  1289
cg@2015
  1290
at:aKey language:language put:value
cg@2015
  1291
    self addKey:aKey.
cg@2032
  1292
    ^ (perLanguageMappings at:language) at:aKey put:value
cg@2015
  1293
!
cg@2015
  1294
cg@2015
  1295
keyAt:index
cg@2015
  1296
    ^ keys at:index.
cg@2015
  1297
!
cg@2015
  1298
cg@2015
  1299
keyAt:index ifAbsent:exceptionalValue
cg@2015
  1300
    ^ keys at:index ifAbsent:exceptionalValue.
cg@2015
  1301
!
cg@2015
  1302
cg@2015
  1303
keys
cg@2015
  1304
    ^ keys
cg@2015
  1305
!
cg@2015
  1306
cg@2015
  1307
languages
cg@2015
  1308
    ^ languages
cg@2015
  1309
!
cg@2015
  1310
cg@2015
  1311
removeKey:aKey
cg@2015
  1312
    keys remove:aKey ifAbsent:[].
cg@2032
  1313
    perLanguageMappings do:[:eachMapping |
cg@2015
  1314
        eachMapping removeKey:aKey ifAbsent:[].
cg@2015
  1315
    ].
cg@2015
  1316
    self changed.
cg@2015
  1317
!
cg@2015
  1318
cg@2015
  1319
size
cg@2015
  1320
    ^ keys size
cg@2015
  1321
! !
cg@2015
  1322
cg@2015
  1323
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'enumerating'!
cg@2015
  1324
cg@2015
  1325
do:aBlock
cg@2015
  1326
    keys do:[:eachKey |
cg@2015
  1327
        aBlock value:(InternationalLanguageTranslationEditor::LanguageMappingRow new 
cg@2015
  1328
                                key:eachKey; mappings:self).
cg@2015
  1329
    ].
cg@2015
  1330
! !
cg@2015
  1331
cg@2015
  1332
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'initialization'!
cg@2015
  1333
cg@2015
  1334
initialize
cg@2015
  1335
    super initialize.
cg@2015
  1336
cg@2015
  1337
    keys := OrderedSet new.
cg@2015
  1338
    languages := OrderedCollection new.
cg@2032
  1339
    perLanguageMappings := Dictionary new.
cg@2032
  1340
    perLanguageInfo := Dictionary new.
cg@2015
  1341
cg@2031
  1342
    self addLanguage:#'de'.
cg@2031
  1343
    self addLanguage:#'fr'.
cg@2031
  1344
    self addLanguage:#'es'.
cg@2031
  1345
    self addLanguage:(Smalltalk language).
cg@2031
  1346
cg@2031
  1347
    "/ self initializeDemoMappings.
cg@2031
  1348
!
cg@2031
  1349
cg@2031
  1350
initializeDemoMappings
cg@2015
  1351
    keys add:'open'.
cg@2015
  1352
    keys add:'close'.
cg@2015
  1353
    keys add:'yes'.
cg@2015
  1354
    keys add:'no'.
cg@2015
  1355
cg@2015
  1356
    self addLanguage:#'de'.
cg@2015
  1357
    self addLanguage:#'fr'.
cg@2015
  1358
cg@2015
  1359
    self at:'open' language:#'de' put:'öffnen'.    
cg@2015
  1360
    self at:'close' language:#'de' put:'schliessen'.    
cg@2015
  1361
    self at:'yes' language:#'de' put:'ja'.    
cg@2015
  1362
    self at:'no' language:#'de' put:'nein'.    
cg@2015
  1363
    self at:'cancel' language:#'de' put:'abbrechen'.    
cg@2015
  1364
cg@2015
  1365
    self at:'open' language:#'fr' put:'ouvrir'.    
cg@2015
  1366
    self at:'close' language:#'fr' put:'fermer'.    
cg@2015
  1367
    self at:'yes' language:#'fr' put:'oui'.    
cg@2015
  1368
    self at:'no' language:#'fr' put:'non'.    
cg@2015
  1369
! !
cg@2015
  1370
cg@2015
  1371
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'private'!
cg@2015
  1372
cg@2015
  1373
atLanguage:lang
cg@2032
  1374
    ^ perLanguageMappings at:lang
cg@2015
  1375
!
cg@2015
  1376
cg@2015
  1377
atLanguageIndex:idx
cg@2015
  1378
    |lang|
cg@2015
  1379
cg@2015
  1380
    lang := languages at:idx.
cg@2015
  1381
    ^ self atLanguage:lang.
cg@2032
  1382
!
cg@2032
  1383
cg@2032
  1384
mappingAtLanguage:lang
cg@2032
  1385
    ^ perLanguageMappings at:lang
cg@2032
  1386
!
cg@2032
  1387
cg@2032
  1388
mappingAtLanguageIndex:idx
cg@2032
  1389
    |lang|
cg@2032
  1390
cg@2032
  1391
    lang := languages at:idx.
cg@2032
  1392
    ^ self mappingAtLanguage:lang.
cg@2015
  1393
! !
cg@2015
  1394
cg@2015
  1395
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'queries'!
cg@2015
  1396
cg@2015
  1397
includesKey:aKey
cg@2015
  1398
    ^ keys includes:aKey
cg@2015
  1399
!
cg@2015
  1400
cg@2015
  1401
includesLanguage:lang
cg@2015
  1402
    ^ languages includes:lang
cg@2015
  1403
!
cg@2015
  1404
cg@2015
  1405
indexOfKey:aKey
cg@2015
  1406
    ^ keys indexOf:aKey
cg@2015
  1407
! !
cg@2015
  1408
cg@2015
  1409
!InternationalLanguageTranslationEditor::LanguageMappingRow methodsFor:'accessing'!
cg@2015
  1410
cg@2015
  1411
atLanguage:language
cg@2032
  1412
    |translation|
cg@2032
  1413
cg@2032
  1414
    translation := (mappings mappingAtLanguage:language) at:key ifAbsent:nil.
cg@2032
  1415
    ^ translation isNil ifTrue:nil ifFalse:[translation printString]
cg@2015
  1416
!
cg@2015
  1417
cg@2015
  1418
columnAt:columnNr
cg@2032
  1419
    ^ (mappings mappingAtLanguageIndex:columnNr-1) at: key ifAbsent:nil
cg@2015
  1420
!
cg@2015
  1421
cg@2015
  1422
key:something
cg@2015
  1423
    key := something.
cg@2015
  1424
!
cg@2015
  1425
cg@2015
  1426
keyString
cg@2032
  1427
    ^ key printString
cg@2015
  1428
!
cg@2015
  1429
cg@2015
  1430
mappings:something
cg@2015
  1431
    mappings := something.
cg@2015
  1432
! !
cg@2015
  1433
cg@2015
  1434
!InternationalLanguageTranslationEditor::UISpecVisitor methodsFor:'accessing'!
cg@2015
  1435
cg@2015
  1436
translatedLabels
cg@2015
  1437
    ^ translatedLabels ? #()
cg@2015
  1438
! !
cg@2015
  1439
cg@2015
  1440
!InternationalLanguageTranslationEditor::UISpecVisitor methodsFor:'visiting'!
cg@2015
  1441
cg@2015
  1442
visitObject:anObject with:aParameter
cg@2033
  1443
    |l|
cg@2033
  1444
cg@2015
  1445
    (anObject isKindOf:UISpecification) ifTrue:[
cg@2015
  1446
        (anObject respondsTo:#translateLabel) ifTrue:[
cg@2015
  1447
            anObject translateLabel == true ifTrue:[
cg@2015
  1448
                translatedLabels isNil ifTrue:[
cg@2015
  1449
                    translatedLabels := Set new.
cg@2015
  1450
                ].
cg@2033
  1451
                l := anObject perform:#label ifNotUnderstood:nil.
cg@2033
  1452
                l notNil ifTrue:[
cg@2033
  1453
                    translatedLabels add:l.
cg@2033
  1454
                ].
cg@2015
  1455
            ].
cg@2015
  1456
        ].
cg@2015
  1457
    ].
cg@2015
  1458
    self visitChildrenOf:anObject.
cg@2015
  1459
! !
cg@2015
  1460
cg@2015
  1461
!InternationalLanguageTranslationEditor class methodsFor:'documentation'!
cg@2015
  1462
cg@2015
  1463
version
cg@2015
  1464
    ^ '$Header$'
cg@2015
  1465
! !