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