833 ! |
833 ! |
834 |
834 |
835 localAt:aKey |
835 localAt:aKey |
836 "translate a string. |
836 "translate a string. |
837 Some special 'intelligence' has been added: |
837 Some special 'intelligence' has been added: |
838 if no value for aKey is found, |
838 if no value for aKey is found, |
839 lookup aKey with first character caseChanged and change the results first characters case. |
839 lookup aKey with first character caseChanged and change the results first characters case. |
840 or aKey is '(...)', then lookup ... wrap () around the result. |
840 or aKey is '(...)', then lookup ... wrap () around the result. |
841 or aKey is '[...]', then lookup ... wrap [] around the result. |
841 or aKey is '[...]', then lookup ... wrap [] around the result. |
842 or aKey is '{...}', then lookup ... wrap {} around the result. |
842 or aKey is '{...}', then lookup ... wrap {} around the result. |
843 or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result. |
843 or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result. |
844 or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
844 or aKey starts with a '*', then lookup aKey without '*' and prepend '*' to the result. |
845 or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
845 or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
846 or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
846 or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
847 or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
847 or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
848 or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
848 or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
849 or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
849 or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
850 or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
850 or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
851 or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result. |
851 or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
852 or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
852 or aKey ends with a '*', then lookup aKey without '*' and append '*' to the result. |
853 or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
853 or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result. |
854 or aKey includes '&', then lookup aKey without '&'. |
854 or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
855 or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
856 or aKey includes '&', then lookup aKey without '&'. |
855 |
857 |
856 This means, that only a single translation is required to provide local translations for |
858 This means, that only a single translation is required to provide local translations for |
857 things like |
859 things like |
858 'search' |
860 'search' |
859 'search:' |
861 'search:' |
860 'search...' |
862 'search...' |
861 " |
863 " |
862 |
864 |
863 |val alternativeKey usedKey idx first last| |
865 |val alternativeKey usedKey idx first last| |
864 |
866 |
865 val := super at:aKey ifAbsent:nil. |
867 val := super at:aKey ifAbsent:nil. |
866 val notNil ifTrue:[ |
868 val notNil ifTrue:[ |
867 ^ val value |
869 ^ val value |
868 ]. |
870 ]. |
869 |
871 |
870 (aKey isString and:[aKey notEmpty]) ifTrue:[ |
872 (aKey isString and:[aKey notEmpty]) ifTrue:[ |
871 first := aKey first. |
873 first := aKey first. |
872 last := aKey last. |
874 last := aKey last. |
873 |
875 |
874 "/ try with case-first swapped... |
876 "/ try with case-first swapped... |
875 first isLetter ifTrue:[ |
877 first isLetter ifTrue:[ |
876 alternativeKey := first isUppercase |
878 alternativeKey := first isUppercase |
877 ifTrue:[aKey asLowercaseFirst] |
879 ifTrue:[aKey asLowercaseFirst] |
878 ifFalse:[aKey asUppercaseFirst]. |
880 ifFalse:[aKey asUppercaseFirst]. |
879 val := super at:alternativeKey ifAbsent:nil. |
881 val := super at:alternativeKey ifAbsent:nil. |
880 val notNil ifTrue:[ |
882 val notNil ifTrue:[ |
881 first isUppercase ifTrue:[ |
883 first isUppercase ifTrue:[ |
882 ^ val asUppercaseFirst |
884 ^ val asUppercaseFirst |
883 ]. |
885 ]. |
884 ^ val asLowercaseFirst. |
886 ^ val asLowercaseFirst. |
885 ]. |
887 ]. |
886 ]. |
888 ]. |
887 |
889 |
888 ((first == $( and:[last == $) ]) |
890 ((first == $( and:[last == $) ]) |
889 or:[ (first == $[ and:[last == $] ]) |
891 or:[ (first == $[ and:[last == $] ]) |
890 or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
892 or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
891 usedKey := aKey copyFrom:2 to:aKey size-1. |
893 usedKey := aKey copyFrom:2 to:aKey size-1. |
892 |
894 |
893 val := self localAt:usedKey. "/ recursion |
895 val := self localAt:usedKey. "/ recursion |
894 val notNil ifTrue:[^ first asString,val,last asString]. |
896 val notNil ifTrue:[^ first asString,val,last asString]. |
895 ]. |
897 ]. |
896 |
898 |
897 last == $. ifTrue:[ |
899 last == $. ifTrue:[ |
898 (aKey endsWith:' ...') ifTrue:[ |
900 (aKey endsWith:' ...') ifTrue:[ |
899 usedKey := aKey copyButLast:4. |
901 usedKey := aKey copyButLast:4. |
900 |
902 |
901 val := self localAt:usedKey. "/ recursion |
903 val := self localAt:usedKey. "/ recursion |
902 val notNil ifTrue:[^ val , ' ...']. |
904 val notNil ifTrue:[^ val , ' ...']. |
903 ]. |
905 ]. |
904 (aKey endsWith:'...') ifTrue:[ |
906 (aKey endsWith:'...') ifTrue:[ |
905 usedKey := aKey copyButLast:3. |
907 usedKey := aKey copyButLast:3. |
906 |
908 |
907 val := self localAt:usedKey. "/ recursion |
909 val := self localAt:usedKey. "/ recursion |
908 val notNil ifTrue:[^ val , '...']. |
910 val notNil ifTrue:[^ val , '...']. |
909 ]. |
911 ]. |
910 ]. |
912 ]. |
911 |
913 |
912 first isSeparator ifTrue:[ |
914 first isSeparator ifTrue:[ |
913 usedKey := aKey withoutLeadingSeparators. |
915 usedKey := aKey withoutLeadingSeparators. |
914 |
916 |
915 val := self localAt:usedKey. "/ recursion |
917 val := self localAt:usedKey. "/ recursion |
916 val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
918 val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
917 ]. |
919 ]. |
918 last isSeparator ifTrue:[ |
920 last isSeparator ifTrue:[ |
919 usedKey := aKey withoutTrailingSeparators. |
921 usedKey := aKey withoutTrailingSeparators. |
920 |
922 |
921 val := self localAt:usedKey. "/ recursion |
923 val := self localAt:usedKey. "/ recursion |
922 val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
924 val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
923 ]. |
925 ]. |
924 |
926 |
925 ('*:=.?!!,-><\' includes:last) ifTrue:[ |
927 ('*:=.?!!,-><\' includes:last) ifTrue:[ |
926 aKey size >= 2 ifTrue:[ |
928 aKey size >= 2 ifTrue:[ |
927 usedKey := aKey copyButLast:1. |
929 usedKey := aKey copyButLast:1. |
928 |
930 |
929 val := self localAt:usedKey. "/ recursion |
931 val := self localAt:usedKey. "/ recursion |
930 val notNil ifTrue:[^ val copyWith:last]. |
932 val notNil ifTrue:[^ val copyWith:last]. |
931 ]. |
933 ]. |
932 ]. |
934 ]. |
933 ('*:=.?!!-><\' includes:first) ifTrue:[ |
935 ('*:=.?!!-><\' includes:first) ifTrue:[ |
934 aKey size >= 2 ifTrue:[ |
936 aKey size >= 2 ifTrue:[ |
935 usedKey := aKey copyFrom:2. |
937 usedKey := aKey copyButFirst:1. |
936 |
938 |
937 val := self localAt:usedKey. "/ recursion |
939 val := self localAt:usedKey. "/ recursion |
938 val notNil ifTrue:[^ first asString , val]. |
940 val notNil ifTrue:[^ first asString , val]. |
939 ]. |
941 ]. |
940 ]. |
942 ]. |
941 |
943 |
942 (first == $( and:[last == $)]) ifTrue:[ |
944 (first == $( and:[last == $)]) ifTrue:[ |
943 usedKey := aKey copyFrom:2 to:(aKey size - 1). |
945 usedKey := aKey copyFrom:2 to:(aKey size - 1). |
944 |
946 |
945 val := self localAt:usedKey. "/ recursion |
947 val := self localAt:usedKey. "/ recursion |
946 val notNil ifTrue:[^ '(' , val , ')']. |
948 val notNil ifTrue:[^ '(' , val , ')']. |
947 ]. |
949 ]. |
948 |
950 |
949 (idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
951 (idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
950 (aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
952 (aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
951 usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
953 usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
952 val := self localAt:usedKey. "/ recursion |
954 val := self localAt:usedKey. "/ recursion |
953 val notNil ifTrue:[^ val]. |
955 val notNil ifTrue:[^ val]. |
954 ]. |
956 ]. |
955 ]. |
957 ]. |
956 ]. |
958 ]. |
957 ^ nil. |
959 ^ nil. |
958 |
960 |
959 "Created: / 18-09-2006 / 17:33:27 / cg" |
961 "Created: / 18-09-2006 / 17:33:27 / cg" |
960 "Modified: / 21-08-2007 / 21:18:12 / cg" |
|
961 "Modified: / 05-08-2010 / 16:52:32 / sr" |
962 "Modified: / 05-08-2010 / 16:52:32 / sr" |
|
963 "Modified: / 27-11-2017 / 15:33:48 / cg" |
962 ! |
964 ! |
963 |
965 |
964 name:aKey default:default |
966 name:aKey default:default |
965 "translate a string. |
967 "translate a string. |
966 Obsolete - use #string:default:" |
968 Obsolete - use #string:default:" |