Tools__InternationalLanguageTranslationEditor.st
author Claus Gittinger <cg@exept.de>
Mon, 06 Mar 2006 09:26:48 +0100
changeset 2015 8f226ff9b5e6
child 2031 85947c4c6502
permissions -rw-r--r--
initial checkin
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@2015
    13
		languageTextModifiedHolder'
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@2015
   554
    super initialize
cg@2015
   555
!
cg@2015
   556
cg@2015
   557
postBuildDataSet:aView
cg@2015
   558
    dataSetView := aView
cg@2015
   559
! !
cg@2015
   560
cg@2015
   561
!InternationalLanguageTranslationEditor methodsFor:'menu actions'!
cg@2015
   562
cg@2015
   563
addLanguage
cg@2015
   564
    |lang|
cg@2015
   565
cg@2015
   566
    lang := Dialog request:'New language (ISO symbol):'.
cg@2015
   567
    lang isEmptyOrNil ifTrue:[^ self].
cg@2015
   568
cg@2015
   569
    (keyStringsToLanguageMappings includesLanguage:lang) ifTrue:[^ self ].
cg@2015
   570
cg@2015
   571
    keyStringsToLanguageMappings addLanguage:lang.
cg@2015
   572
    self languagesList add:lang.
cg@2015
   573
    self shownLanguages add:lang.
cg@2015
   574
    modified := true.
cg@2015
   575
!
cg@2015
   576
cg@2015
   577
addTranslation
cg@2015
   578
    |key index|
cg@2015
   579
cg@2015
   580
    key := Dialog request:'New Key:'.
cg@2015
   581
    (keyStringsToLanguageMappings includesKey:key) ifFalse:[
cg@2015
   582
        keyStringsToLanguageMappings addKey:key.
cg@2015
   583
        modified := true.
cg@2015
   584
    ].
cg@2015
   585
    index := keyStringsToLanguageMappings indexOfKey:key.
cg@2015
   586
cg@2015
   587
    self selectedKeyRow value:index
cg@2015
   588
!
cg@2015
   589
cg@2015
   590
extractTranslationsFromClass
cg@2015
   591
    |aClass newTranslations|
cg@2015
   592
cg@2015
   593
    aClass := Dialog 
cg@2015
   594
                requestClass:'Class to extract translations from:'
cg@2015
   595
                okLabel:'OK' 
cg@2015
   596
                initialAnswer:(lastExtractedClass ? LastExtractedClass).
cg@2015
   597
    aClass isNil ifTrue:[^ self ].
cg@2015
   598
cg@2015
   599
    lastExtractedClass := LastExtractedClass := aClass.
cg@2015
   600
cg@2015
   601
    newTranslations := Set new.
cg@2015
   602
cg@2015
   603
    self withWaitCursorDo:[
cg@2015
   604
        "/ now, the hard part:
cg@2015
   605
        "/ possible translations are in the specs,
cg@2015
   606
        "/ and all arguments to (resources string:) messages.
cg@2015
   607
        aClass instAndClassMethodsDo:[:eachMethod |
cg@2015
   608
            newTranslations addAll:( self extractTranslationsFromMethod:eachMethod ).
cg@2015
   609
        ].
cg@2015
   610
    ].
cg@2015
   611
cg@2015
   612
    newTranslations := newTranslations select:[:k | k notEmpty and:[k isBlank not]].
cg@2015
   613
    newTranslations := newTranslations select:[:k | (keyStringsToLanguageMappings includesKey:k) not].
cg@2015
   614
    newTranslations notEmpty ifTrue:[
cg@2015
   615
        newTranslations := newTranslations asSortedCollection.
cg@2015
   616
        keyStringsToLanguageMappings addKeys:newTranslations.
cg@2015
   617
        modified := true.
cg@2015
   618
    ].
cg@2015
   619
!
cg@2015
   620
cg@2015
   621
menuNew
cg@2015
   622
    modified ifTrue:[
cg@2015
   623
        (Dialog 
cg@2015
   624
            confirm:(resources stringWithCRs:'Modified translations have not been changed.\\Create new translations set anyway ?')
cg@2015
   625
            default:false) ifFalse:[^ self].
cg@2015
   626
    ].
cg@2015
   627
cg@2015
   628
    keyStringsToLanguageMappings initialize.
cg@2015
   629
    keyStringsToLanguageMappings changed.
cg@2015
   630
cg@2015
   631
    self languagesList contents:self keyStringAndLanguageSelectionTable languages.
cg@2015
   632
    self shownLanguages contents:self keyStringAndLanguageSelectionTable languages.
cg@2015
   633
    modified := false.
cg@2015
   634
!
cg@2015
   635
cg@2015
   636
menuOpen
cg@2015
   637
    |fn|
cg@2015
   638
cg@2015
   639
    fn := Dialog 
cg@2015
   640
        requestFileName:'Name of resource file:'
cg@2015
   641
        default:nil 
cg@2015
   642
        pattern:'*.rs'.
cg@2015
   643
cg@2015
   644
    fn isEmptyOrNil ifTrue:[^ self ].
cg@2015
   645
    fn := fn asFilename.
cg@2015
   646
    fn exists ifFalse:[^ self ].
cg@2015
   647
cg@2015
   648
    self readResourceFile:fn
cg@2015
   649
!
cg@2015
   650
cg@2015
   651
menuSave
cg@2015
   652
    "This method was generated by the Browser.
cg@2015
   653
     It will be invoked when the menu-item 'save' is selected."
cg@2015
   654
cg@2015
   655
    "/ change below and add any actions as required here ...
cg@2015
   656
    self warn:'no action for ''save'' available.'.
cg@2015
   657
!
cg@2015
   658
cg@2015
   659
menuSaveAs
cg@2015
   660
    "This method was generated by the Browser.
cg@2015
   661
     It will be invoked when the menu-item 'saveAs' is selected."
cg@2015
   662
cg@2015
   663
    "/ change below and add any actions as required here ...
cg@2015
   664
    self warn:'no action for ''saveAs'' available.'.
cg@2015
   665
!
cg@2015
   666
cg@2015
   667
openAboutThisApplication
cg@2015
   668
    "This method was generated by the Browser.
cg@2015
   669
     It will be invoked when the menu-item 'help-about' is selected."
cg@2015
   670
cg@2015
   671
    "/ could open a customized aboutBox here ...
cg@2015
   672
    super openAboutThisApplication
cg@2015
   673
!
cg@2015
   674
cg@2015
   675
openDocumentation
cg@2015
   676
    "This method was generated by the Browser.
cg@2015
   677
     It will be invoked when the menu-item 'help-documentation' is selected."
cg@2015
   678
cg@2015
   679
    "/ change below as required ...
cg@2015
   680
cg@2015
   681
    "/ to open an HTML viewer on some document (under 'doc/online/<language>/' ):
cg@2015
   682
    HTMLDocumentView openFullOnDocumentationFile:'TOP.html'.
cg@2015
   683
cg@2015
   684
    "/ add application-specific help files under the 'doc/online/<language>/help/appName'
cg@2015
   685
    "/ directory, and open a viewer with:
cg@2015
   686
    "/ HTMLDocumentView openFullOnDocumentationFile:'help/<MyApplication>/TOP.html'.
cg@2015
   687
!
cg@2015
   688
cg@2015
   689
readResourceFile:aFilename
cg@2015
   690
    |inStream lineString|
cg@2015
   691
cg@2015
   692
    aFilename exists ifFalse:[^ self ].
cg@2015
   693
cg@2015
   694
    inStream := aFilename readStream.
cg@2015
   695
    [inStream atEnd] whileFalse:[
cg@2015
   696
        lineString := inStream nextLine.
cg@2015
   697
        (lineString notEmpty 
cg@2015
   698
        and:[ (lineString startsWith:';') not ]) ifTrue:[
cg@2015
   699
            (lineString startsWith:'#encoding ') ifTrue:[
cg@2015
   700
self halt.
cg@2015
   701
            ] ifFalse:[
cg@2015
   702
self halt.
cg@2015
   703
            ].
cg@2015
   704
        ].
cg@2015
   705
    ].
cg@2015
   706
    inStream close.
cg@2015
   707
!
cg@2015
   708
cg@2015
   709
removeLanguage
cg@2015
   710
    "automatically generated by UIEditor ..."
cg@2015
   711
cg@2015
   712
    "*** the code below performs no action"
cg@2015
   713
    "*** (except for some feedback on the Transcript)"
cg@2015
   714
    "*** Please change as required and accept in the browser."
cg@2015
   715
    "*** (and replace this comment by something more useful ;-)"
cg@2015
   716
cg@2015
   717
    "action to be added ..."
cg@2015
   718
cg@2015
   719
    Transcript showCR:self class name, ': action for #removeLanguage ...'.
cg@2015
   720
!
cg@2015
   721
cg@2015
   722
removeTranslation
cg@2015
   723
    |rowSelectionIndex selectedKey|
cg@2015
   724
cg@2015
   725
    rowSelectionIndex := self selectedKeyRow value.
cg@2015
   726
    rowSelectionIndex ~~ 0 ifTrue:[
cg@2015
   727
        selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex ifAbsent:nil.
cg@2015
   728
        (Dialog confirm:(resources string:'Really remove key %1' with:selectedKey)) ifTrue:[
cg@2015
   729
            keyStringsToLanguageMappings removeKey:selectedKey.
cg@2015
   730
        ].
cg@2015
   731
    ].
cg@2015
   732
!
cg@2015
   733
cg@2015
   734
runApplicationAndCollectTranslations
cg@2015
   735
    |applicationClass newTranslations pseudoPack app|
cg@2015
   736
cg@2015
   737
    monitoredApplication notNil ifTrue:[
cg@2015
   738
        monitoredApplication terminate.
cg@2015
   739
        [monitoredApplication notNil] whileTrue:[
cg@2015
   740
            Delay waitForSeconds:0.1
cg@2015
   741
        ].
cg@2015
   742
    ].
cg@2015
   743
cg@2015
   744
    applicationClass := Dialog 
cg@2015
   745
                requestClass:'Application class to start and collect translations from:'
cg@2015
   746
                okLabel:'OK' 
cg@2015
   747
                initialAnswer:(lastExtractedApplicationClass ? LastExtractedApplicationClass ).
cg@2015
   748
    applicationClass isNil ifTrue:[^ self ].
cg@2015
   749
cg@2015
   750
    lastExtractedApplicationClass := LastExtractedApplicationClass := applicationClass.
cg@2015
   751
cg@2015
   752
    newTranslations := Set new.
cg@2015
   753
cg@2015
   754
    pseudoPack := AccessCollectingPseudoResourcePack new.
cg@2015
   755
    pseudoPack realResourcePack:(applicationClass classResources).
cg@2015
   756
cg@2015
   757
    self stopApplicationIconVisibleHolder value:true.
cg@2015
   758
cg@2015
   759
    monitoredApplication := [
cg@2015
   760
        [
cg@2015
   761
            app := applicationClass new.
cg@2015
   762
            app open.
cg@2015
   763
            app window waitUntilVisible.
cg@2015
   764
            app window waitUntilClosed.
cg@2015
   765
        ] ensure:[
cg@2015
   766
            app closeRequest.
cg@2015
   767
            self stopApplicationIconVisibleHolder value:false.
cg@2015
   768
            monitoredApplication := nil.
cg@2015
   769
        ].
cg@2015
   770
    ] fork.
cg@2015
   771
! !
cg@2015
   772
cg@2015
   773
!InternationalLanguageTranslationEditor methodsFor:'menus dynamic'!
cg@2015
   774
cg@2015
   775
disableLanguageDisplayFor:lang
cg@2015
   776
    self shownLanguages remove:lang ifAbsent:[]
cg@2015
   777
!
cg@2015
   778
cg@2015
   779
enableLanguageDisplayFor:newLang
cg@2015
   780
    |shownLanguagesInOrder|
cg@2015
   781
cg@2015
   782
    (self shownLanguages includes:newLang) ifFalse:[
cg@2015
   783
        shownLanguagesInOrder := self languagesList
cg@2015
   784
                                    select:[:lang | (self shownLanguages includes:lang)
cg@2015
   785
                                                    or:[ lang = newLang ]].
cg@2015
   786
        self shownLanguages contents:shownLanguagesInOrder.
cg@2015
   787
    ]
cg@2015
   788
!
cg@2015
   789
cg@2015
   790
isLanguageShown:lang
cg@2015
   791
    ^ self shownLanguages includes:lang
cg@2015
   792
!
cg@2015
   793
cg@2015
   794
shownLanguagesMenu
cg@2015
   795
    <resource: #programMenu >
cg@2015
   796
cg@2015
   797
    ^ [
cg@2015
   798
        |m selected|
cg@2015
   799
cg@2015
   800
        m := Menu new.
cg@2015
   801
cg@2015
   802
        self languagesList do:[:lang |
cg@2015
   803
            |item|
cg@2015
   804
cg@2015
   805
            item := MenuItem label:lang.
cg@2015
   806
            item indication:(self languageShownHolderFor:lang).
cg@2015
   807
            item hideMenuOnActivated:false.    
cg@2015
   808
            m addItem:item.
cg@2015
   809
        ].
cg@2015
   810
        m
cg@2015
   811
    ].
cg@2015
   812
!
cg@2015
   813
cg@2015
   814
toggleLanguageDisplayFor:lang
cg@2015
   815
    (self shownLanguages includes:lang) ifTrue:[
cg@2015
   816
        self disableLanguageDisplayFor:lang
cg@2015
   817
    ] ifFalse:[
cg@2015
   818
        self enableLanguageDisplayFor:lang
cg@2015
   819
    ].
cg@2015
   820
! !
cg@2015
   821
cg@2015
   822
!InternationalLanguageTranslationEditor methodsFor:'private-key extraction'!
cg@2015
   823
cg@2015
   824
extractTranslationsFromHelpSpecMethod:aMethod
cg@2015
   825
    |codeStrings matcher parseTree resourceKeys|
cg@2015
   826
cg@2015
   827
    parseTree := RBParser 
cg@2015
   828
            parseMethod:aMethod source 
cg@2015
   829
            onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos.
cg@2015
   830
                                  nil].
cg@2015
   831
    parseTree isNil ifTrue:[^ #() ].
cg@2015
   832
cg@2015
   833
    codeStrings  := 
cg@2015
   834
        #(
cg@2015
   835
                '`@dict addPairsFrom: `#helpKeysAndStrings'
cg@2015
   836
        ).
cg@2015
   837
cg@2015
   838
    resourceKeys := Set new.
cg@2015
   839
cg@2015
   840
    matcher := ParseTreeSearcher new.
cg@2015
   841
    matcher 
cg@2015
   842
        matchesAnyOf: codeStrings 
cg@2015
   843
        do: [:aNode :answer |
cg@2015
   844
                |sel argNode arg|
cg@2015
   845
cg@2015
   846
                sel := aNode selector.
cg@2015
   847
                (sel startsWith:'addPairsFrom:') ifTrue:[
cg@2015
   848
                    argNode := aNode arguments at:1.
cg@2015
   849
                    argNode isLiteral ifTrue:[
cg@2015
   850
                        arg := argNode value.
cg@2015
   851
                        arg isArray ifTrue:[
cg@2015
   852
                            arg doWithIndex:[:el :index |
cg@2015
   853
                                index even ifTrue:[
cg@2015
   854
                                    el isString ifTrue:[    
cg@2015
   855
                                        resourceKeys add:el.
cg@2015
   856
                                    ]
cg@2015
   857
                                ].
cg@2015
   858
                            ].
cg@2015
   859
                        ] ifFalse:[
cg@2015
   860
                            Transcript 
cg@2015
   861
                                showCR:(resources 
cg@2015
   862
                                        string:'Cannot derive resourceKey from non-array in %1 in %2'
cg@2015
   863
                                        with:argNode formattedCode
cg@2015
   864
                                        with:aMethod selector).
cg@2015
   865
                        ].
cg@2015
   866
                    ] ifFalse:[
cg@2015
   867
                        Transcript 
cg@2015
   868
                            showCR:(resources 
cg@2015
   869
                                        string:'Cannot derive resourceKey from non-literal: %1 in %2'
cg@2015
   870
                                        with:argNode formattedCode
cg@2015
   871
                                        with:aMethod selector).
cg@2015
   872
                    ].
cg@2015
   873
                ].
cg@2015
   874
                aNode
cg@2015
   875
            ].
cg@2015
   876
cg@2015
   877
    matcher executeTree: parseTree initialAnswer: nil.
cg@2015
   878
    ^ resourceKeys
cg@2015
   879
!
cg@2015
   880
cg@2015
   881
extractTranslationsFromMenuSpecMethod:aMethod
cg@2015
   882
    |menu resourceKeys|
cg@2015
   883
cg@2015
   884
    menu := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
   885
    menu isNil ifTrue:[ ^ #() ].
cg@2015
   886
cg@2015
   887
    (menu isKindOf:Menu) ifFalse:[
cg@2015
   888
        menu := Menu new fromLiteralArrayEncoding:menu
cg@2015
   889
    ].
cg@2015
   890
cg@2015
   891
    resourceKeys := Set new.
cg@2015
   892
    menu allItemsDo:[:aMenuItem |
cg@2015
   893
        aMenuItem translateLabel ifTrue:[
cg@2015
   894
            aMenuItem isSeparatorItem ifFalse:[
cg@2015
   895
                resourceKeys add:aMenuItem label.
cg@2015
   896
            ]
cg@2015
   897
        ]
cg@2015
   898
    ].
cg@2015
   899
    ^ resourceKeys
cg@2015
   900
!
cg@2015
   901
cg@2015
   902
extractTranslationsFromMethod:aMethod
cg@2015
   903
    |mResources|
cg@2015
   904
cg@2015
   905
    mResources := aMethod resources.
cg@2015
   906
    mResources notNil ifTrue:[
cg@2015
   907
        (mResources includesKey:#menu) ifTrue:[
cg@2015
   908
             ^ self extractTranslationsFromMenuSpecMethod:aMethod.
cg@2015
   909
        ].
cg@2015
   910
        (mResources includesKey:#canvas) ifTrue:[
cg@2015
   911
             ^ self extractTranslationsFromUISpecMethod:aMethod.
cg@2015
   912
        ].
cg@2015
   913
        (mResources includesKey:#help) ifTrue:[
cg@2015
   914
             ^ self extractTranslationsFromHelpSpecMethod:aMethod.
cg@2015
   915
        ].
cg@2015
   916
        (mResources includesKey:#tableColumns) ifTrue:[
cg@2015
   917
             ^ self extractTranslationsFromTableColumnsSpecMethod:aMethod.
cg@2015
   918
        ].
cg@2015
   919
cg@2015
   920
        ^ self extractTranslationsFromSpecMethod:aMethod.
cg@2015
   921
    ].
cg@2015
   922
    ^ self extractTranslationsFromMethodsCode:aMethod
cg@2015
   923
!
cg@2015
   924
cg@2015
   925
extractTranslationsFromMethodsCode:aMethod
cg@2015
   926
"/method:mthd selector:sel inClass:cls matchesParseTreeMatcher:aMatcher
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
                'resources `@msg: `@args'
cg@2015
   938
                'self resources `@msg: `@args'
cg@2015
   939
                'self class resources `@msg: `@args'
cg@2015
   940
                'self classResources `@msg: `@args'
cg@2015
   941
        ).
cg@2015
   942
cg@2015
   943
    resourceKeys := Set new.
cg@2015
   944
cg@2015
   945
    matcher := ParseTreeSearcher new.
cg@2015
   946
    matcher 
cg@2015
   947
        matchesAnyOf: codeStrings 
cg@2015
   948
        do: [:aNode :answer |
cg@2015
   949
                |sel keyStringArgNode keyStringArg|
cg@2015
   950
cg@2015
   951
                sel := aNode selector.
cg@2015
   952
                ((sel startsWith:'string:') or:[(sel startsWith:'at:')]) ifTrue:[
cg@2015
   953
                    keyStringArgNode := aNode arguments at:1.
cg@2015
   954
                    keyStringArgNode isLiteral ifTrue:[
cg@2015
   955
                        keyStringArg := keyStringArgNode value.
cg@2015
   956
                        keyStringArg isString ifTrue:[
cg@2015
   957
                            resourceKeys add:keyStringArg.
cg@2015
   958
                        ] ifFalse:[
cg@2015
   959
                            Transcript 
cg@2015
   960
                                showCR:(resources 
cg@2015
   961
                                        string:'Cannot derive resourceKey from non-string: %1 in %2'
cg@2015
   962
                                        with:keyStringArgNode formattedCode
cg@2015
   963
                                        with:aMethod selector).
cg@2015
   964
                        ].
cg@2015
   965
                    ] ifFalse:[
cg@2015
   966
                        Transcript 
cg@2015
   967
                            showCR:(resources 
cg@2015
   968
                                        string:'Cannot derive resourceKey from non-literal: %1 in %2'
cg@2015
   969
                                        with:keyStringArgNode formattedCode
cg@2015
   970
                                        with:aMethod selector).
cg@2015
   971
                    ].
cg@2015
   972
                ].
cg@2015
   973
                aNode
cg@2015
   974
            ].
cg@2015
   975
cg@2015
   976
    matcher executeTree: parseTree initialAnswer: nil.
cg@2015
   977
    ^ resourceKeys
cg@2015
   978
!
cg@2015
   979
cg@2015
   980
extractTranslationsFromSpecMethod:aMethod
cg@2015
   981
    ^ #()
cg@2015
   982
!
cg@2015
   983
cg@2015
   984
extractTranslationsFromTableColumnsSpecMethod:aMethod
cg@2015
   985
    |columnDescription resourceKeys|
cg@2015
   986
cg@2015
   987
    columnDescription := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
   988
    columnDescription isNil ifTrue:[ ^ #() ].
cg@2015
   989
cg@2015
   990
    (columnDescription first isKindOf:DataSetColumnSpec) ifFalse:[
cg@2015
   991
        columnDescription := columnDescription collect:[:el | DataSetColumnSpec new fromLiteralArrayEncoding:el].
cg@2015
   992
    ].
cg@2015
   993
cg@2015
   994
    resourceKeys := Set new.
cg@2015
   995
    columnDescription do:[:aColumnSpec |
cg@2015
   996
        aColumnSpec translateLabel ifTrue:[
cg@2015
   997
            resourceKeys add:aColumnSpec label.
cg@2015
   998
        ]
cg@2015
   999
    ].
cg@2015
  1000
    ^ resourceKeys
cg@2015
  1001
!
cg@2015
  1002
cg@2015
  1003
extractTranslationsFromUISpecMethod:aMethod
cg@2015
  1004
    |spec resourceKeys visitor|
cg@2015
  1005
cg@2015
  1006
    spec := aMethod mclass theNonMetaclass perform:aMethod selector.
cg@2015
  1007
    spec isNil ifTrue:[ ^ #() ].
cg@2015
  1008
cg@2015
  1009
    (spec isKindOf:UISpecification) ifFalse:[
cg@2015
  1010
        spec := UISpecification from:spec
cg@2015
  1011
    ].
cg@2015
  1012
cg@2015
  1013
    resourceKeys := Set new.
cg@2015
  1014
cg@2015
  1015
    visitor := UISpecVisitor new.
cg@2015
  1016
    spec acceptVisitor:visitor.
cg@2015
  1017
cg@2015
  1018
    ^ visitor translatedLabels
cg@2015
  1019
! !
cg@2015
  1020
cg@2015
  1021
!InternationalLanguageTranslationEditor methodsFor:'queries'!
cg@2015
  1022
cg@2015
  1023
hasUnsavedChanges
cg@2015
  1024
    ^ modified
cg@2015
  1025
! !
cg@2015
  1026
cg@2015
  1027
!InternationalLanguageTranslationEditor methodsFor:'specs-dynamic'!
cg@2015
  1028
cg@2015
  1029
columnInRow:row at:colIndex
cg@2015
  1030
    |lang|
cg@2015
  1031
cg@2015
  1032
    lang := self languageAtCol:colIndex.
cg@2015
  1033
    ^ row atLanguage:lang
cg@2015
  1034
!
cg@2015
  1035
cg@2015
  1036
getBackgroundForRow:row rowNr:rowNr col:colIndex
cg@2015
  1037
    |lang|
cg@2015
  1038
cg@2015
  1039
    colIndex == 1 ifTrue:[^ nil].
cg@2015
  1040
    lang := self languageAtCol:colIndex.
cg@2015
  1041
    ^ (row atLanguage:lang) isNil ifTrue:[Color red lightened] ifFalse:nil
cg@2015
  1042
!
cg@2015
  1043
cg@2015
  1044
keyStringAndLanguageSelectionTableColumnDescription
cg@2015
  1045
    |spec|
cg@2015
  1046
cg@2015
  1047
    spec := OrderedCollection new.
cg@2015
  1048
cg@2015
  1049
    spec add:
cg@2015
  1050
      #(DataSetColumnSpec
cg@2015
  1051
         label: 'Key'
cg@2015
  1052
         labelAlignment: center
cg@2015
  1053
         labelButtonType: Button
cg@2015
  1054
         minWidth: 50
cg@2015
  1055
         model: keyStringInRow:
cg@2015
  1056
         isResizeable: true
cg@2015
  1057
         canSelect: true
cg@2015
  1058
         showRowSeparator: true
cg@2015
  1059
         showColSeparator: true
cg@2015
  1060
       ).
cg@2015
  1061
cg@2015
  1062
    self shownLanguages do:[:lang |
cg@2015
  1063
        |entry|
cg@2015
  1064
cg@2015
  1065
        entry :=
cg@2015
  1066
              #(DataSetColumnSpec
cg@2015
  1067
                 label: lang
cg@2015
  1068
                 labelAlignment: center
cg@2015
  1069
                 labelButtonType: Button
cg@2015
  1070
                 minWidth: 50
cg@2015
  1071
                 model: #columnInRow:at:
cg@2015
  1072
                 canSelect: true
cg@2015
  1073
                 isResizeable: true
cg@2015
  1074
                 showRowSeparator: true
cg@2015
  1075
                 showColSeparator: true
cg@2015
  1076
                 backgroundSelector: #getBackgroundForRow:rowNr:col:
cg@2015
  1077
               ).
cg@2015
  1078
        entry := entry copy.
cg@2015
  1079
        entry replaceAll:#lang with:lang.
cg@2015
  1080
        spec add: entry 
cg@2015
  1081
    ].
cg@2015
  1082
    ^ spec
cg@2015
  1083
!
cg@2015
  1084
cg@2015
  1085
keyStringInRow:row
cg@2015
  1086
    ^ row keyString
cg@2015
  1087
! !
cg@2015
  1088
cg@2015
  1089
!InternationalLanguageTranslationEditor methodsFor:'user actions'!
cg@2015
  1090
cg@2015
  1091
selectionChanged
cg@2015
  1092
    |rowSelectionIndex colSelectionIndex language selectedKey originalText languageText
cg@2015
  1093
     answer|
cg@2015
  1094
cg@2015
  1095
    colSelectionIndex := dataSetView selectedColIndex.
cg@2015
  1096
    language := colSelectionIndex > 1 ifTrue:[ shownLanguages at:colSelectionIndex-1 ] ifFalse:nil.
cg@2015
  1097
cg@2015
  1098
    rowSelectionIndex := self selectedKeyRow value.
cg@2015
  1099
    rowSelectionIndex ~~ 0 ifTrue:[
cg@2015
  1100
        selectedKey := keyStringsToLanguageMappings keyAt:rowSelectionIndex.
cg@2015
  1101
        originalText := selectedKey storeString.
cg@2015
  1102
        language notNil ifTrue:[
cg@2015
  1103
            languageText := keyStringsToLanguageMappings at:selectedKey language:language.
cg@2015
  1104
            languageText notNil ifTrue:[
cg@2015
  1105
                languageText := languageText storeString.
cg@2015
  1106
            ]
cg@2015
  1107
        ]
cg@2015
  1108
    ].
cg@2015
  1109
cg@2015
  1110
    self originalTextModifiedHolder value ifTrue:[ 
cg@2015
  1111
        answer := OptionBox 
cg@2015
  1112
                      request:'Accept changed original text (key) ?' 
cg@2015
  1113
                      label:'Original text (key) changed'
cg@2015
  1114
                      image:(WarningBox iconBitmap)
cg@2015
  1115
                      buttonLabels:#('Cancel' 'Accept' 'Accept As New')
cg@2015
  1116
                      values:#(nil #accept #acceptAsNew)
cg@2015
  1117
                      default:#acceptAsNew.
cg@2015
  1118
cg@2015
  1119
        answer isNil ifTrue:[^ self ].
cg@2015
  1120
        answer == #accept ifTrue:[
cg@2015
  1121
self halt.        ].
cg@2015
  1122
        answer == #acceptAsNew ifTrue:[
cg@2015
  1123
self halt.        ].
cg@2015
  1124
    ].
cg@2015
  1125
    self languageTextModifiedHolder value ifTrue:[ self halt.
cg@2015
  1126
        (Dialog confirm:'Accept changed translation ?') ifTrue:[
cg@2015
  1127
            self halt.
cg@2015
  1128
        ]
cg@2015
  1129
    ].
cg@2015
  1130
cg@2015
  1131
    self originalTextHolder value:originalText.
cg@2015
  1132
    self languageTextHolder value:languageText.
cg@2015
  1133
cg@2015
  1134
    self originalTextModifiedHolder value:false.
cg@2015
  1135
    self languageTextModifiedHolder value:false.
cg@2015
  1136
!
cg@2015
  1137
cg@2015
  1138
shownLanguagesChanged
cg@2015
  1139
    self keyStringAndLanguageSelectionTableColumnDescriptionHolder 
cg@2015
  1140
        value:(self keyStringAndLanguageSelectionTableColumnDescription).
cg@2015
  1141
!
cg@2015
  1142
cg@2015
  1143
stopApplication
cg@2015
  1144
    |p|
cg@2015
  1145
cg@2015
  1146
    (p := monitoredApplication) notNil ifTrue:[
cg@2015
  1147
        p terminate.
cg@2015
  1148
    ].
cg@2015
  1149
! !
cg@2015
  1150
cg@2015
  1151
!InternationalLanguageTranslationEditor::AccessCollectingPseudoResourcePack methodsFor:'accessing'!
cg@2015
  1152
cg@2015
  1153
realResourcePack:something
cg@2015
  1154
    realResourcePack := something.
cg@2015
  1155
! !
cg@2015
  1156
cg@2015
  1157
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings class methodsFor:'instance creation'!
cg@2015
  1158
cg@2015
  1159
new
cg@2015
  1160
    ^ self basicNew initialize
cg@2015
  1161
! !
cg@2015
  1162
cg@2015
  1163
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'accessing'!
cg@2015
  1164
cg@2015
  1165
addKey:aKey
cg@2015
  1166
    keys add:aKey.
cg@2015
  1167
    self changed.
cg@2015
  1168
!
cg@2015
  1169
cg@2015
  1170
addKeys:aCollectionOfKey
cg@2015
  1171
    keys addAll:aCollectionOfKey.
cg@2015
  1172
    self changed.
cg@2015
  1173
!
cg@2015
  1174
cg@2015
  1175
addLanguage:lang
cg@2015
  1176
    languages add:lang.
cg@2015
  1177
    languageMappings at:lang put:(Dictionary new).
cg@2015
  1178
!
cg@2015
  1179
cg@2015
  1180
at:aKey language:language
cg@2015
  1181
    ^ (languageMappings at:language) at:aKey ifAbsent:nil
cg@2015
  1182
!
cg@2015
  1183
cg@2015
  1184
at:aKey language:language put:value
cg@2015
  1185
    self addKey:aKey.
cg@2015
  1186
    ^ (languageMappings at:language) at:aKey put:value
cg@2015
  1187
!
cg@2015
  1188
cg@2015
  1189
keyAt:index
cg@2015
  1190
    ^ keys at:index.
cg@2015
  1191
!
cg@2015
  1192
cg@2015
  1193
keyAt:index ifAbsent:exceptionalValue
cg@2015
  1194
    ^ keys at:index ifAbsent:exceptionalValue.
cg@2015
  1195
!
cg@2015
  1196
cg@2015
  1197
keys
cg@2015
  1198
    ^ keys
cg@2015
  1199
!
cg@2015
  1200
cg@2015
  1201
languages
cg@2015
  1202
    ^ languages
cg@2015
  1203
!
cg@2015
  1204
cg@2015
  1205
removeKey:aKey
cg@2015
  1206
    keys remove:aKey ifAbsent:[].
cg@2015
  1207
    languageMappings do:[:eachMapping |
cg@2015
  1208
        eachMapping removeKey:aKey ifAbsent:[].
cg@2015
  1209
    ].
cg@2015
  1210
    self changed.
cg@2015
  1211
!
cg@2015
  1212
cg@2015
  1213
size
cg@2015
  1214
    ^ keys size
cg@2015
  1215
! !
cg@2015
  1216
cg@2015
  1217
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'enumerating'!
cg@2015
  1218
cg@2015
  1219
do:aBlock
cg@2015
  1220
    keys do:[:eachKey |
cg@2015
  1221
        aBlock value:(InternationalLanguageTranslationEditor::LanguageMappingRow new 
cg@2015
  1222
                                key:eachKey; mappings:self).
cg@2015
  1223
    ].
cg@2015
  1224
! !
cg@2015
  1225
cg@2015
  1226
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'initialization'!
cg@2015
  1227
cg@2015
  1228
initialize
cg@2015
  1229
    super initialize.
cg@2015
  1230
cg@2015
  1231
    keys := OrderedSet new.
cg@2015
  1232
    languages := OrderedCollection new.
cg@2015
  1233
    languageMappings := Dictionary new.
cg@2015
  1234
cg@2015
  1235
    keys add:'open'.
cg@2015
  1236
    keys add:'close'.
cg@2015
  1237
    keys add:'yes'.
cg@2015
  1238
    keys add:'no'.
cg@2015
  1239
cg@2015
  1240
    self addLanguage:#'de'.
cg@2015
  1241
    self addLanguage:#'fr'.
cg@2015
  1242
cg@2015
  1243
    self at:'open' language:#'de' put:'öffnen'.    
cg@2015
  1244
    self at:'close' language:#'de' put:'schliessen'.    
cg@2015
  1245
    self at:'yes' language:#'de' put:'ja'.    
cg@2015
  1246
    self at:'no' language:#'de' put:'nein'.    
cg@2015
  1247
    self at:'cancel' language:#'de' put:'abbrechen'.    
cg@2015
  1248
cg@2015
  1249
    self at:'open' language:#'fr' put:'ouvrir'.    
cg@2015
  1250
    self at:'close' language:#'fr' put:'fermer'.    
cg@2015
  1251
    self at:'yes' language:#'fr' put:'oui'.    
cg@2015
  1252
    self at:'no' language:#'fr' put:'non'.    
cg@2015
  1253
! !
cg@2015
  1254
cg@2015
  1255
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'private'!
cg@2015
  1256
cg@2015
  1257
atLanguage:lang
cg@2015
  1258
    ^ languageMappings at:lang
cg@2015
  1259
!
cg@2015
  1260
cg@2015
  1261
atLanguageIndex:idx
cg@2015
  1262
    |lang|
cg@2015
  1263
cg@2015
  1264
    lang := languages at:idx.
cg@2015
  1265
    ^ self atLanguage:lang.
cg@2015
  1266
! !
cg@2015
  1267
cg@2015
  1268
!InternationalLanguageTranslationEditor::KeyStringsToLanguageMappings methodsFor:'queries'!
cg@2015
  1269
cg@2015
  1270
includesKey:aKey
cg@2015
  1271
    ^ keys includes:aKey
cg@2015
  1272
!
cg@2015
  1273
cg@2015
  1274
includesLanguage:lang
cg@2015
  1275
    ^ languages includes:lang
cg@2015
  1276
!
cg@2015
  1277
cg@2015
  1278
indexOfKey:aKey
cg@2015
  1279
    ^ keys indexOf:aKey
cg@2015
  1280
! !
cg@2015
  1281
cg@2015
  1282
!InternationalLanguageTranslationEditor::LanguageMappingRow methodsFor:'accessing'!
cg@2015
  1283
cg@2015
  1284
atLanguage:language
cg@2015
  1285
    ^ (mappings atLanguage:language) at: key ifAbsent:nil
cg@2015
  1286
!
cg@2015
  1287
cg@2015
  1288
columnAt:columnNr
cg@2015
  1289
    ^ (mappings atLanguageIndex:columnNr-1) at: key ifAbsent:nil
cg@2015
  1290
!
cg@2015
  1291
cg@2015
  1292
key:something
cg@2015
  1293
    key := something.
cg@2015
  1294
!
cg@2015
  1295
cg@2015
  1296
keyString
cg@2015
  1297
    ^ key
cg@2015
  1298
!
cg@2015
  1299
cg@2015
  1300
mappings:something
cg@2015
  1301
    mappings := something.
cg@2015
  1302
! !
cg@2015
  1303
cg@2015
  1304
!InternationalLanguageTranslationEditor::UISpecVisitor methodsFor:'accessing'!
cg@2015
  1305
cg@2015
  1306
translatedLabels
cg@2015
  1307
    ^ translatedLabels ? #()
cg@2015
  1308
! !
cg@2015
  1309
cg@2015
  1310
!InternationalLanguageTranslationEditor::UISpecVisitor methodsFor:'visiting'!
cg@2015
  1311
cg@2015
  1312
visitObject:anObject with:aParameter
cg@2015
  1313
    (anObject isKindOf:UISpecification) ifTrue:[
cg@2015
  1314
        (anObject respondsTo:#translateLabel) ifTrue:[
cg@2015
  1315
            anObject translateLabel == true ifTrue:[
cg@2015
  1316
                translatedLabels isNil ifTrue:[
cg@2015
  1317
                    translatedLabels := Set new.
cg@2015
  1318
                ].
cg@2015
  1319
                translatedLabels add:anObject label.
cg@2015
  1320
            ].
cg@2015
  1321
        ].
cg@2015
  1322
    ].
cg@2015
  1323
    self visitChildrenOf:anObject.
cg@2015
  1324
! !
cg@2015
  1325
cg@2015
  1326
!InternationalLanguageTranslationEditor class methodsFor:'documentation'!
cg@2015
  1327
cg@2015
  1328
version
cg@2015
  1329
    ^ '$Header$'
cg@2015
  1330
! !