--- a/ResourcePack.st Sat Dec 13 03:01:42 2014 +0100
+++ b/ResourcePack.st Sun Dec 14 14:47:21 2014 +0100
@@ -664,6 +664,89 @@
]
"Modified: / 06-02-2014 / 15:33:03 / cg"
+!
+
+resourceFileEntryFor:keyString to:nationalString
+ "generate a line for a translation file, which defines a translation
+ from keyString to nationalString.
+ Naivly, this could be a simple line containing the two storeStrings
+ separated by a space. However, it is better to first cut of any leading
+ and trailing spaces and special characters, such as ':*.,' etc."
+
+ ^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString)
+!
+
+resourceFileStringFor:aString
+ "generate a key or value entry for a translation file, for aString.
+ Naivly, this could be a simple the storeString.
+ However, it is better to first cut of any leading
+ and trailing spaces and special characters, sch as ':*.,' etc."
+
+ ^ (self shortenedKeyFor:aString) storeString
+
+ "
+ self resourceFileStringFor:' foo: '
+ self resourceFileStringFor:' foo bar: '
+ "
+!
+
+shortenedKeyFor:aKey
+ "if
+ aKey is '(...)', then return '...'
+ if aKey is '[...]', then return '...'
+ if aKey is '{...}', then return '...'
+ if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it
+
+ This means, that only a single translation is required to provide local translations for
+ things like
+ 'search'
+ 'search:'
+ 'search...'
+ "
+
+ |idx idx1 idx2 first last keySize|
+
+ first := aKey first.
+ last := aKey last.
+ keySize := aKey size.
+
+ ((first == $( and:[last == $) ])
+ or:[ (first == $[ and:[last == $] ])
+ or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[
+ ^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1).
+ ].
+
+ idx1 := aKey findFirst:[:ch | ch isSeparator not].
+ idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize.
+ (idx1 > 1 or:[idx2 < keySize]) ifTrue:[
+ ^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2)
+ ].
+
+ idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not].
+ idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize.
+ (idx1 > 1 or:[idx2 < keySize]) ifTrue:[
+ ^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2)
+ ].
+
+ "/ change duplicated &'s to single
+ (idx := aKey indexOf:$&) ~~ 0 ifTrue:[
+ (aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[
+ ^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1).
+ ].
+ ].
+ ^ aKey.
+
+ "
+ 'abcde' findFirst:[:ch | 'bcd' includes:ch]
+ 'abcde' indexOfAny:'bcd'
+
+ self shortenedKeyFor:'abc'
+ self shortenedKeyFor:' abc '
+ self shortenedKeyFor:'(abc)'
+ self shortenedKeyFor:'abc...'
+ self shortenedKeyFor:'(abc...)'
+ self shortenedKeyFor:'abc:*'
+ "
! !
!ResourcePack methodsFor:'accessing'!
@@ -1478,11 +1561,11 @@
!ResourcePack class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.159 2014-12-06 13:10:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.160 2014-12-14 13:47:21 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.159 2014-12-06 13:10:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.160 2014-12-14 13:47:21 cg Exp $'
! !