Tools__InternationalLanguageTranslationEditor.st
changeset 3284 4de194c0ee74
parent 3283 74fcc1bf0fab
child 3285 5b8697869e72
equal deleted inserted replaced
3283:74fcc1bf0fab 3284:4de194c0ee74
  2289     codeStrings  :=
  2289     codeStrings  :=
  2290         #(
  2290         #(
  2291                 'resources `@msg: `@args'
  2291                 'resources `@msg: `@args'
  2292                 'self resources `@msg: `@args'
  2292                 'self resources `@msg: `@args'
  2293                 'self class resources `@msg: `@args'
  2293                 'self class resources `@msg: `@args'
       
  2294                 'self class classResources `@msg: `@args'
  2294                 'self classResources `@msg: `@args'
  2295                 'self classResources `@msg: `@args'
  2295                 '`V classResources `@msg: `@args'
  2296                 '`V classResources `@msg: `@args'
  2296         ).
  2297         ).
  2297 
  2298 
  2298     resourceKeys := Set new.
  2299     resourceKeys := Set new.
  2304                 |sel keyStringArgNode keyStringArg|
  2305                 |sel keyStringArgNode keyStringArg|
  2305 
  2306 
  2306                 sel := aNode selector.
  2307                 sel := aNode selector.
  2307                 ((sel startsWith:'string:') or:[(sel startsWith:'at:') or:[sel startsWith:'stringWithCRs:']]) ifTrue:[
  2308                 ((sel startsWith:'string:') or:[(sel startsWith:'at:') or:[sel startsWith:'stringWithCRs:']]) ifTrue:[
  2308                     keyStringArgNode := aNode arguments at:1.
  2309                     keyStringArgNode := aNode arguments at:1.
  2309                     keyStringArgNode isLiteral ifTrue:[
  2310                     (keyStringArg := self literalStringOrStringConcatenation:keyStringArgNode) notNil ifTrue:[
  2310                         keyStringArg := keyStringArgNode value.
  2311                         resourceKeys add:keyStringArg.
  2311                         keyStringArg isString ifTrue:[
       
  2312                             resourceKeys add:keyStringArg.
       
  2313                         ] ifFalse:[
       
  2314                             Transcript
       
  2315                                 showCR:(resources
       
  2316                                         string:'Cannot derive resourceKey from non-string: %1 in %2'
       
  2317                                         with:keyStringArgNode formattedCode
       
  2318                                         with:aMethod whoString).
       
  2319                         ].
       
  2320                     ] ifFalse:[
  2312                     ] ifFalse:[
  2321                         Transcript
  2313                         Transcript
  2322                             showCR:(resources 
  2314                             showCR:(resources
  2323                                         string:'Cannot derive resourceKey from non-literal: %1 in %2'
  2315                                     string:'[LanguageTranslator] warning: Cannot derive resourceKey from non-string: %1 in %2'
  2324                                         with:keyStringArgNode formattedCode
  2316                                     with:keyStringArgNode formattedCode
  2325                                         with:aMethod whoString).
  2317                                     with:aMethod whoString).
  2326                     ].
  2318                     ].
  2327                 ].
  2319                 ].
  2328                 aNode
  2320                 aNode
  2329             ].
  2321             ].
  2330 
  2322 
  2371 
  2363 
  2372     visitor := UISpecVisitor new.
  2364     visitor := UISpecVisitor new.
  2373     spec acceptVisitor:visitor.
  2365     spec acceptVisitor:visitor.
  2374 
  2366 
  2375     ^ visitor translatedLabels
  2367     ^ visitor translatedLabels
       
  2368 !
       
  2369 
       
  2370 isLiteralStringOrStringConcatenation:aParseNode
       
  2371     aParseNode isLiteralString ifTrue:[^ true].
       
  2372     (aParseNode isMessage and:[aParseNode selector == #,]) ifTrue:[
       
  2373         self halt.
       
  2374     ].
       
  2375     ^ false
       
  2376 !
       
  2377 
       
  2378 literalStringOrStringConcatenation:aParseNode
       
  2379     "nil if not a literal or a string concatenation"
       
  2380     
       
  2381     aParseNode isLiteralString ifTrue:[^ aParseNode value].
       
  2382     (aParseNode isMessage and:[aParseNode selector == #,]) ifTrue:[
       
  2383         |leftString rightString|
       
  2384         
       
  2385         aParseNode receiver isLiteralString ifTrue:[
       
  2386             leftString := aParseNode receiver value
       
  2387         ] ifFalse:[
       
  2388             leftString := self literalStringOrStringConcatenation:aParseNode receiver.
       
  2389         ].
       
  2390         aParseNode arguments first isLiteralString ifTrue:[
       
  2391             rightString := aParseNode arguments first value
       
  2392         ] ifFalse:[
       
  2393             rightString := self literalStringOrStringConcatenation:aParseNode arguments first.
       
  2394         ].
       
  2395         (leftString notNil and:[rightString notNil]) ifTrue:[
       
  2396             ^ leftString , rightString
       
  2397         ].
       
  2398     ].
       
  2399     ^ nil
  2376 ! !
  2400 ! !
  2377 
  2401 
  2378 !InternationalLanguageTranslationEditor methodsFor:'queries'!
  2402 !InternationalLanguageTranslationEditor methodsFor:'queries'!
  2379 
  2403 
  2380 autoAccept
  2404 autoAccept