2709 cr. |
2709 cr. |
2710 ]. |
2710 ]. |
2711 ! |
2711 ! |
2712 |
2712 |
2713 readResourceFile:aFilename asLanguage:lang |
2713 readResourceFile:aFilename asLanguage:lang |
2714 |resourcePack inStream lineString encoding decoder sortedKeys remainingKeys| |
2714 |resourcePack inStream lineString encoding |
|
2715 decoder sortedKeys remainingKeys lineNr| |
2715 |
2716 |
2716 aFilename exists ifFalse:[ |
2717 aFilename exists ifFalse:[ |
2717 Dialog information:(resources string:'Language file: "%1" does not exist' with:aFilename baseName). |
2718 Dialog information:(resources string:'Language file: "%1" does not exist' with:aFilename baseName). |
2718 ^ self |
2719 ^ self |
2719 ]. |
2720 ]. |
2720 |
2721 |
2721 resourcePack := ResourcePack new. |
2722 resourcePack := ResourcePack new. |
2722 |
2723 |
2723 inStream := aFilename readStream. |
2724 inStream := LineNumberReadStream on:(aFilename readStream). |
2724 [inStream atEnd] whileFalse:[ |
2725 [inStream atEnd] whileFalse:[ |
2725 lineString := inStream nextLine. |
2726 lineNr := inStream lineNumber. |
2726 (lineString notEmpty |
2727 lineString := inStream nextLine. |
2727 and:[ (lineString startsWith:';') not and:[ (lineString startsWith:'"/') not]]) ifTrue:[ |
2728 (lineString notEmpty |
2728 ((lineString startsWith:'#') and:[(lineString startsWith:'#(') not]) ifTrue:[ |
2729 and:[ (lineString startsWith:';') not and:[ (lineString startsWith:'"/') not]]) ifTrue:[ |
2729 lineString := (lineString copyFrom:2) withoutSeparators. |
2730 ((lineString startsWith:'#') and:[(lineString startsWith:'#(') not]) ifTrue:[ |
2730 (lineString startsWith:'encoding ') ifTrue:[ |
2731 lineString := (lineString copyFrom:2) withoutSeparators. |
2731 encoding := ResourcePack extractEncodingFromLine:lineString. |
2732 (lineString startsWith:'encoding ') ifTrue:[ |
2732 decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
2733 encoding := ResourcePack extractEncodingFromLine:lineString. |
2733 ]. |
2734 decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
2734 ] ifFalse:[ |
2735 ]. |
2735 ResourcePack |
2736 ] ifFalse:[ |
2736 processResourceLine:lineString |
2737 ResourcePack |
2737 encoding:decoder |
2738 processResourceLine:lineString |
2738 file:aFilename pathName |
2739 encoding:decoder |
2739 printErrorWith:[:msg | Transcript showCR:msg ] |
2740 file:aFilename pathName |
2740 for:resourcePack |
2741 printErrorWith:[:msg | |
2741 keepUselessTranslations:true. |
2742 Transcript |
2742 ]. |
2743 showCR:'%1[%2]: %3' |
2743 ]. |
2744 with:(aFilename baseName) |
|
2745 with:lineNr |
|
2746 with:msg |
|
2747 ] |
|
2748 for:resourcePack |
|
2749 keepUselessTranslations:true. |
|
2750 ]. |
|
2751 ]. |
2744 ]. |
2752 ]. |
2745 inStream close. |
2753 inStream close. |
2746 |
2754 |
2747 sortedKeys := (resourcePack keys select:[:k | k isString]) asSortedCollection. |
2755 sortedKeys := (resourcePack keys select:[:k | k isString]) asSortedCollection. |
2748 remainingKeys := resourcePack keys select:[:k | k isString not]. |
2756 remainingKeys := resourcePack keys select:[:k | k isString not]. |
2749 |
2757 |
2750 keyStringsToLanguageMappings atLanguage: lang putFilename: aFilename. |
2758 keyStringsToLanguageMappings atLanguage: lang putFilename: aFilename. |
2751 keyStringsToLanguageMappings atLanguage: lang putEncoder: decoder. |
2759 keyStringsToLanguageMappings atLanguage: lang putEncoder: decoder. |
2752 |
2760 |
2753 sortedKeys do:[:k | |
2761 sortedKeys do:[:k | |
2754 keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k) sendChange:false |
2762 keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k) sendChange:false |
2755 ]. |
2763 ]. |
2756 remainingKeys do:[:k | |
2764 remainingKeys do:[:k | |
2757 keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k) sendChange:false |
2765 keyStringsToLanguageMappings at:k language:lang put:(resourcePack at:k) sendChange:false |
2758 ]. |
2766 ]. |
2759 keyStringsToLanguageMappings changed. |
2767 keyStringsToLanguageMappings changed. |
|
2768 |
|
2769 "Modified: / 20-09-2018 / 11:09:39 / Claus Gittinger" |
2760 ! |
2770 ! |
2761 |
2771 |
2762 saveLanguage: lang |
2772 saveLanguage: lang |
2763 "Saves the language in the fileName from where the language resource was obtained." |
2773 "Saves the language in the fileName from where the language resource was obtained." |
2764 |filename| |
2774 |filename| |