ResourcePack.st
changeset 6661 2f05e09f8a31
parent 6650 4a076bbc32f6
child 6767 9a77194dae66
equal deleted inserted replaced
6659:21975a0db156 6661:2f05e09f8a31
   662             ]
   662             ]
   663         ]
   663         ]
   664     ]
   664     ]
   665 
   665 
   666     "Modified: / 06-02-2014 / 15:33:03 / cg"
   666     "Modified: / 06-02-2014 / 15:33:03 / cg"
       
   667 !
       
   668 
       
   669 resourceFileEntryFor:keyString to:nationalString
       
   670     "generate a line for a translation file, which defines a translation
       
   671      from keyString to nationalString.
       
   672      Naivly, this could be a simple line containing the two storeStrings
       
   673      separated by a space. However, it is better to first cut of any leading
       
   674      and trailing spaces and special characters, such as ':*.,' etc."
       
   675 
       
   676     ^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString) 
       
   677 !
       
   678 
       
   679 resourceFileStringFor:aString
       
   680     "generate a key or value entry for a translation file, for aString.
       
   681      Naivly, this could be a simple the storeString.
       
   682      However, it is better to first cut of any leading
       
   683      and trailing spaces and special characters, sch as ':*.,' etc."
       
   684 
       
   685     ^ (self shortenedKeyFor:aString) storeString
       
   686 
       
   687     "
       
   688      self resourceFileStringFor:'  foo:   ' 
       
   689      self resourceFileStringFor:'  foo bar:   '  
       
   690     "
       
   691 !
       
   692 
       
   693 shortenedKeyFor:aKey
       
   694     "if
       
   695           aKey is '(...)', then return '...'
       
   696           if aKey is '[...]', then return '...'
       
   697           if aKey is '{...}', then return '...'
       
   698           if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it
       
   699 
       
   700      This means, that only a single translation is required to provide local translations for
       
   701      things like 
       
   702         'search'
       
   703         'search:'
       
   704         'search...'
       
   705     "
       
   706 
       
   707     |idx idx1 idx2 first last keySize|
       
   708 
       
   709     first := aKey first.
       
   710     last := aKey last.
       
   711     keySize := aKey size.
       
   712 
       
   713     ((first == $( and:[last == $) ])
       
   714     or:[ (first == $[ and:[last == $] ])
       
   715     or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[
       
   716         ^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1).
       
   717     ].
       
   718 
       
   719     idx1 := aKey findFirst:[:ch | ch isSeparator not].
       
   720     idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize.
       
   721     (idx1 > 1 or:[idx2 < keySize]) ifTrue:[
       
   722         ^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2)
       
   723     ].
       
   724 
       
   725     idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not].
       
   726     idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize.
       
   727     (idx1 > 1 or:[idx2 < keySize]) ifTrue:[
       
   728         ^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2)
       
   729     ].
       
   730 
       
   731     "/ change duplicated &'s to single
       
   732     (idx := aKey indexOf:$&) ~~ 0 ifTrue:[
       
   733         (aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[
       
   734             ^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1).
       
   735         ].
       
   736     ].
       
   737     ^ aKey.
       
   738 
       
   739     "
       
   740      'abcde' findFirst:[:ch | 'bcd' includes:ch]
       
   741      'abcde' indexOfAny:'bcd'
       
   742 
       
   743      self shortenedKeyFor:'abc'        
       
   744      self shortenedKeyFor:'   abc    ' 
       
   745      self shortenedKeyFor:'(abc)'           
       
   746      self shortenedKeyFor:'abc...'          
       
   747      self shortenedKeyFor:'(abc...)'        
       
   748      self shortenedKeyFor:'abc:*'        
       
   749     "
   667 ! !
   750 ! !
   668 
   751 
   669 !ResourcePack methodsFor:'accessing'!
   752 !ResourcePack methodsFor:'accessing'!
   670 
   753 
   671 array:anArray
   754 array:anArray
  1476 ! !
  1559 ! !
  1477 
  1560 
  1478 !ResourcePack class methodsFor:'documentation'!
  1561 !ResourcePack class methodsFor:'documentation'!
  1479 
  1562 
  1480 version
  1563 version
  1481     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.159 2014-12-06 13:10:18 cg Exp $'
  1564     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.160 2014-12-14 13:47:21 cg Exp $'
  1482 !
  1565 !
  1483 
  1566 
  1484 version_CVS
  1567 version_CVS
  1485     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.159 2014-12-06 13:10:18 cg Exp $'
  1568     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.160 2014-12-14 13:47:21 cg Exp $'
  1486 ! !
  1569 ! !
  1487 
  1570 
  1488 
  1571 
  1489 ResourcePack initialize!
  1572 ResourcePack initialize!