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 |