598 by the MenuEditor of ST/X." |
598 by the MenuEditor of ST/X." |
599 |
599 |
600 "Do not manually edit this!! If it is corrupted, |
600 "Do not manually edit this!! If it is corrupted, |
601 the MenuEditor may not be able to read the specification." |
601 the MenuEditor may not be able to read the specification." |
602 |
602 |
|
603 |
603 " |
604 " |
604 MenuEditor new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#mainMenu |
605 MenuEditor new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#mainMenu |
605 (Menu new fromLiteralArrayEncoding:(Tools::InternationalLanguageTranslationEditor mainMenu)) startUp |
606 (Menu new fromLiteralArrayEncoding:(Tools::InternationalLanguageTranslationEditor mainMenu)) startUp |
606 " |
607 " |
607 |
608 |
608 <resource: #menu> |
609 <resource: #menu> |
609 |
610 |
610 ^ |
611 ^ |
611 #(Menu |
612 #(Menu |
612 ( |
613 ( |
613 (MenuItem |
614 (MenuItem |
614 label: 'File' |
615 label: 'File' |
615 translateLabel: true |
616 submenu: |
616 submenu: |
617 (Menu |
617 (Menu |
618 ( |
618 ( |
619 (MenuItem |
619 (MenuItem |
620 label: 'New' |
620 label: 'New' |
621 itemValue: menuNew |
621 itemValue: menuNew |
622 ) |
622 translateLabel: true |
623 (MenuItem |
623 ) |
624 label: '-' |
624 (MenuItem |
625 ) |
625 label: '-' |
626 (MenuItem |
626 ) |
627 label: 'Open Resources for Package or Project...' |
627 (MenuItem |
628 itemValue: menuOpenByPackage |
628 label: 'Open Resources for Package or Project...' |
629 ) |
629 itemValue: menuOpenByPackage |
630 (MenuItem |
630 translateLabel: true |
631 label: 'Open Resource File...' |
631 ) |
632 itemValue: menuOpen |
632 (MenuItem |
633 ) |
633 label: 'Open Resource File...' |
634 (MenuItem |
634 itemValue: menuOpen |
635 label: '-' |
635 translateLabel: true |
636 ) |
636 ) |
637 (MenuItem |
637 (MenuItem |
638 label: 'Save All Resource Files' |
638 label: '-' |
639 itemValue: menuSaveAll |
639 ) |
640 ) |
640 (MenuItem |
641 (MenuItem |
641 label: 'Save All Resource Files' |
642 label: 'Save Resource File' |
642 itemValue: menuSaveAll |
643 itemValue: menuSave |
643 translateLabel: true |
644 ) |
644 ) |
645 (MenuItem |
645 (MenuItem |
646 label: 'Save Resource File As...' |
646 label: 'Save Resource File' |
647 itemValue: menuSaveAs |
647 itemValue: menuSave |
648 ) |
648 translateLabel: true |
649 (MenuItem |
649 ) |
650 label: '-' |
650 (MenuItem |
651 ) |
651 label: 'Save Resource File As...' |
652 (MenuItem |
652 itemValue: menuSaveAs |
653 label: 'Import existing translations from file...' |
653 translateLabel: true |
654 itemValue: importExistingTranslationsFromFile |
654 ) |
655 ) |
655 (MenuItem |
656 (MenuItem |
656 label: '-' |
657 label: '-' |
657 ) |
658 ) |
658 (MenuItem |
659 (MenuItem |
659 label: 'Import existing translations from file...' |
660 label: 'Set Current NameSpace' |
660 itemValue: importExistingTranslationsFromFile |
661 itemValue: changeLastNameSpace |
661 translateLabel: true |
662 ) |
662 ) |
663 (MenuItem |
663 (MenuItem |
664 label: 'Set Current Package' |
664 label: '-' |
665 itemValue: changeLastPackage |
665 ) |
666 isVisible: #false |
666 (MenuItem |
667 ) |
667 label: 'Set Current NameSpace' |
668 (MenuItem |
668 itemValue: changeLastNameSpace |
669 label: '-' |
669 translateLabel: true |
670 ) |
670 ) |
671 (MenuItem |
671 (MenuItem |
672 label: 'Exit' |
672 label: 'Set Current Package' |
673 itemValue: closeRequest |
673 itemValue: changeLastPackage |
674 ) |
674 translateLabel: true |
675 ) |
675 isVisible: #false |
676 nil |
676 ) |
677 nil |
677 (MenuItem |
678 ) |
678 label: '-' |
679 ) |
679 ) |
680 (MenuItem |
680 (MenuItem |
681 label: 'View' |
681 label: 'Exit' |
682 submenu: |
682 itemValue: closeRequest |
683 (Menu |
683 translateLabel: true |
684 ( |
684 ) |
685 (MenuItem |
685 ) |
686 label: 'Show Missing Translations Only' |
686 nil |
687 indication: showMissingTranslationsOnly |
687 nil |
688 ) |
688 ) |
689 (MenuItem |
689 ) |
690 label: '-' |
690 (MenuItem |
691 ) |
691 label: 'View' |
692 (MenuItem |
692 translateLabel: true |
693 label: 'Shown Languages' |
693 submenu: |
694 submenuChannel: shownLanguagesMenu |
694 (Menu |
695 ) |
695 ( |
696 ) |
696 (MenuItem |
697 nil |
697 label: 'Show Missing Translations Only' |
698 nil |
698 translateLabel: true |
699 ) |
699 indication: showMissingTranslationsOnly |
700 ) |
700 ) |
701 (MenuItem |
701 (MenuItem |
702 label: 'Languages' |
702 label: '-' |
703 submenu: |
703 ) |
704 (Menu |
704 (MenuItem |
705 ( |
705 label: 'Shown Languages' |
706 (MenuItem |
706 translateLabel: true |
707 label: 'Add Language...' |
707 submenuChannel: shownLanguagesMenu |
708 itemValue: addLanguage |
708 ) |
709 ) |
709 ) |
710 (MenuItem |
710 nil |
711 label: 'Remove Language...' |
711 nil |
712 itemValue: removeLanguage |
712 ) |
713 ) |
713 ) |
714 ) |
714 (MenuItem |
715 nil |
715 label: 'Languages' |
716 nil |
716 translateLabel: true |
717 ) |
717 submenu: |
718 ) |
718 (Menu |
719 (MenuItem |
719 ( |
720 label: 'Translations' |
720 (MenuItem |
721 submenuChannel: translationsMenuSpec |
721 label: 'Add Language...' |
722 ) |
722 itemValue: addLanguage |
723 (MenuItem |
723 translateLabel: true |
724 label: 'Preferences' |
724 ) |
725 submenu: |
725 (MenuItem |
726 (Menu |
726 label: 'Remove Language...' |
727 ( |
727 itemValue: removeLanguage |
728 (MenuItem |
728 translateLabel: true |
729 label: 'Auto Accept Changes' |
729 ) |
730 indication: autoAcceptHolder |
730 ) |
731 ) |
731 nil |
732 (MenuItem |
732 nil |
733 label: 'Search For Similar Translations' |
733 ) |
734 indication: searchForSimilarTranslationEnableHolder |
734 ) |
735 ) |
735 (MenuItem |
736 (MenuItem |
736 label: 'Translations' |
737 label: 'Always Write UTF8' |
737 translateLabel: true |
738 indication: alwaysWriteUTF8Holder |
738 submenu: |
739 ) |
739 (Menu |
740 ) |
740 ( |
741 nil |
741 (MenuItem |
742 nil |
742 label: 'Add Translation...' |
743 ) |
743 itemValue: addTranslation |
744 ) |
744 translateLabel: true |
745 (MenuItem |
745 ) |
746 label: 'Help' |
746 (MenuItem |
747 startGroup: right |
747 label: 'Remove Translation...' |
748 submenu: |
748 itemValue: removeTranslation |
749 (Menu |
749 translateLabel: true |
750 ( |
750 ) |
751 (MenuItem |
751 (MenuItem |
752 label: 'Documentation' |
752 label: '-' |
753 itemValue: openDocumentation |
753 ) |
754 ) |
754 (MenuItem |
755 (MenuItem |
755 label: 'Extract from Class...' |
756 label: '-' |
756 itemValue: extractTranslationsFromClass |
757 ) |
757 translateLabel: true |
758 (MenuItem |
758 ) |
759 label: 'About this Application...' |
759 (MenuItem |
760 itemValue: openAboutThisApplication |
760 label: 'Extract from Project...' |
761 ) |
761 itemValue: extractTranslationsFromProject |
762 ) |
762 translateLabel: true |
763 nil |
763 ) |
764 nil |
764 (MenuItem |
765 ) |
765 label: 'Extract from NameSpace...' |
766 ) |
766 itemValue: extractTranslationsFromNameSpace |
767 ) |
767 translateLabel: true |
768 nil |
768 ) |
769 nil |
769 (MenuItem |
|
770 label: '-' |
|
771 ) |
|
772 (MenuItem |
|
773 label: 'Run Application and Collect Translations...' |
|
774 itemValue: runApplicationAndCollectTranslations |
|
775 translateLabel: true |
|
776 ) |
|
777 ) |
|
778 nil |
|
779 nil |
|
780 ) |
|
781 ) |
|
782 (MenuItem |
|
783 label: 'Preferences' |
|
784 translateLabel: true |
|
785 submenu: |
|
786 (Menu |
|
787 ( |
|
788 (MenuItem |
|
789 label: 'Auto Accept Changes' |
|
790 translateLabel: true |
|
791 indication: autoAcceptHolder |
|
792 ) |
|
793 (MenuItem |
|
794 label: 'Search For Similar Translations' |
|
795 translateLabel: true |
|
796 indication: searchForSimilarTranslationEnableHolder |
|
797 ) |
|
798 (MenuItem |
|
799 label: 'Always Write UTF8' |
|
800 translateLabel: true |
|
801 indication: alwaysWriteUTF8Holder |
|
802 ) |
|
803 ) |
|
804 nil |
|
805 nil |
|
806 ) |
|
807 ) |
|
808 (MenuItem |
|
809 label: 'Help' |
|
810 translateLabel: true |
|
811 startGroup: right |
|
812 submenu: |
|
813 (Menu |
|
814 ( |
|
815 (MenuItem |
|
816 label: 'Documentation' |
|
817 itemValue: openDocumentation |
|
818 translateLabel: true |
|
819 ) |
|
820 (MenuItem |
|
821 label: '-' |
|
822 ) |
|
823 (MenuItem |
|
824 label: 'About this Application...' |
|
825 itemValue: openAboutThisApplication |
|
826 translateLabel: true |
|
827 ) |
|
828 ) |
|
829 nil |
|
830 nil |
|
831 ) |
|
832 ) |
|
833 ) |
|
834 nil |
|
835 nil |
|
836 ) |
770 ) |
837 ! |
771 ! |
838 |
772 |
839 menuItemsEditLanguage |
773 menuItemsEditLanguage |
840 "This resource specification was automatically generated |
774 "This resource specification was automatically generated |
932 ) |
866 ) |
933 ) |
867 ) |
934 nil |
868 nil |
935 nil |
869 nil |
936 ) |
870 ) |
|
871 ! |
|
872 |
|
873 translationsMenuSpec |
|
874 "This resource specification was automatically generated |
|
875 by the MenuEditor of ST/X." |
|
876 |
|
877 "Do not manually edit this!! If it is corrupted, |
|
878 the MenuEditor may not be able to read the specification." |
|
879 |
|
880 |
|
881 " |
|
882 MenuEditor new openOnClass:Tools::InternationalLanguageTranslationEditor andSelector:#translationsMenuSpec |
|
883 (Menu new fromLiteralArrayEncoding:(Tools::InternationalLanguageTranslationEditor translationsMenuSpec)) startUp |
|
884 " |
|
885 |
|
886 <resource: #menu> |
|
887 |
|
888 ^ |
|
889 #(Menu |
|
890 ( |
|
891 (MenuItem |
|
892 label: 'Add Translation...' |
|
893 itemValue: addTranslation |
|
894 ) |
|
895 (MenuItem |
|
896 label: 'Remove Translation...' |
|
897 itemValue: removeTranslation |
|
898 ) |
|
899 (MenuItem |
|
900 label: '-' |
|
901 ) |
|
902 (MenuItem |
|
903 label: 'Extract from Class...' |
|
904 itemValue: extractTranslationsFromClass |
|
905 ) |
|
906 (MenuItem |
|
907 label: 'Extract from Project...' |
|
908 itemValue: extractTranslationsFromProject |
|
909 ) |
|
910 (MenuItem |
|
911 label: 'Extract from NameSpace...' |
|
912 itemValue: extractTranslationsFromNameSpace |
|
913 ) |
|
914 (MenuItem |
|
915 label: '-' |
|
916 ) |
|
917 (MenuItem |
|
918 label: 'Run Application and Collect Translations...' |
|
919 itemValue: runApplicationAndCollectTranslations |
|
920 ) |
|
921 (MenuItem |
|
922 label: '-' |
|
923 ) |
|
924 (MenuItem |
|
925 label: 'Generate Missing Translations' |
|
926 itemValue: generateMissingTranslations |
|
927 ) |
|
928 (MenuItem |
|
929 label: 'Generate Missing Translations Slice' |
|
930 submenuChannel: menuSliceTranslateGenerate |
|
931 isMenuSlice: true |
|
932 ) |
|
933 ) |
|
934 nil |
|
935 nil |
|
936 ) |
937 ! ! |
937 ! ! |
938 |
938 |
939 !InternationalLanguageTranslationEditor class methodsFor:'startup'! |
939 !InternationalLanguageTranslationEditor class methodsFor:'startup'! |
940 |
940 |
941 openOnFile:aFilename |
941 openOnFile:aFilename |
1693 lastExtractedProject := LastExtractedProject := projectID. |
1693 lastExtractedProject := LastExtractedProject := projectID. |
1694 |
1694 |
1695 newTranslations := Set new. |
1695 newTranslations := Set new. |
1696 |
1696 |
1697 Smalltalk allClassesDo:[:eachClass | |
1697 Smalltalk allClassesDo:[:eachClass | |
1698 eachClass theNonMetaclass package == projectID ifTrue:[ |
1698 eachClass theNonMetaclass instAndClassMethodsDo:[:eachMethod | |
1699 "/ eachClass isLoaded ifTrue:[ self halt. ]. |
1699 eachMethod package == projectID ifTrue:[ |
1700 newTranslations addAll:( self extractTranslationsFromClass:eachClass theNonMetaclass). |
1700 newTranslations addAll:( self extractTranslationsFromMethod:eachMethod ). |
1701 ] |
1701 ] |
|
1702 ]. |
1702 ]. |
1703 ]. |
1703 |
1704 |
1704 self addAllTranslations:newTranslations. |
1705 self addAllTranslations:newTranslations. |
1705 |
1706 |
1706 "Modified: / 16-02-2015 / 16:54:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1707 "Modified: / 19-02-2015 / 11:44:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1708 ! |
|
1709 |
|
1710 generateMissingTranslations: keys for: languages using: translator |
|
1711 keys do:[:string | |
|
1712 languages do:[:lang | |
|
1713 | translation | |
|
1714 |
|
1715 translation := keyStringsToLanguageMappings at:string language:lang. |
|
1716 translation isNil ifTrue:[ |
|
1717 translation := translator value: lang value: string. |
|
1718 translation notNil ifTrue:[ |
|
1719 keyStringsToLanguageMappings at: string language: lang put: translation. |
|
1720 ]. |
|
1721 ]. |
|
1722 ]. |
|
1723 ]. |
|
1724 |
|
1725 "Created: / 19-02-2015 / 12:31:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1726 ! |
|
1727 |
|
1728 generateMissingTranslationsFor: languages |
|
1729 self |
|
1730 generateMissingTranslations: keyStringsToLanguageMappings keys |
|
1731 for: languages |
|
1732 using: [ :lang :string | '**%1** %2' bindWith: lang asUppercase with: string ] |
|
1733 |
|
1734 "Created: / 19-02-2015 / 12:39:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1735 ! |
|
1736 |
|
1737 generateMissingTranslationsForAll |
|
1738 self generateMissingTranslationsFor: keyStringsToLanguageMappings languages |
|
1739 |
|
1740 "Created: / 19-02-2015 / 12:40:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1707 ! |
1741 ! |
1708 |
1742 |
1709 importExistingTranslationsFromFile |
1743 importExistingTranslationsFromFile |
1710 self information:'The import function is not available in this release'. |
1744 self information:'The import function is not available in this release'. |
1711 ! |
1745 ! |
2208 extractTranslationsFromMethodsCode:aMethod |
2259 extractTranslationsFromMethodsCode:aMethod |
2209 "/method:mthd selector:sel inClass:cls matchesParseTreeMatcher:aMatcher |
2260 "/method:mthd selector:sel inClass:cls matchesParseTreeMatcher:aMatcher |
2210 |codeStrings matcher parseTree resourceKeys| |
2261 |codeStrings matcher parseTree resourceKeys| |
2211 |
2262 |
2212 parseTree := RBParser |
2263 parseTree := RBParser |
2213 parseMethod:aMethod source |
2264 parseMethod:aMethod source |
2214 onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos. |
2265 onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos. |
2215 nil]. |
2266 nil]. |
2216 parseTree isNil ifTrue:[^ #() ]. |
2267 parseTree isNil ifTrue:[^ #() ]. |
2217 |
2268 |
2218 codeStrings := |
2269 codeStrings := |
2219 #( |
2270 #( |
2220 'resources `@msg: `@args' |
2271 'resources `@msg: `@args' |
2221 'self resources `@msg: `@args' |
2272 'self resources `@msg: `@args' |
2222 'self class resources `@msg: `@args' |
2273 'self class resources `@msg: `@args' |
2223 'self classResources `@msg: `@args' |
2274 'self classResources `@msg: `@args' |
2224 ). |
2275 ). |
2225 |
2276 |
2226 resourceKeys := Set new. |
2277 resourceKeys := Set new. |
2227 |
2278 |
2228 matcher := ParseTreeSearcher new. |
2279 matcher := ParseTreeSearcher new. |
2229 matcher |
2280 matcher |
2230 matchesAnyOf: codeStrings |
2281 matchesAnyOf: codeStrings |
2231 do: [:aNode :answer | |
2282 do: [:aNode :answer | |
2232 |sel keyStringArgNode keyStringArg| |
2283 |sel keyStringArgNode keyStringArg| |
2233 |
2284 |
2234 sel := aNode selector. |
2285 sel := aNode selector. |
2235 ((sel startsWith:'string:') or:[(sel startsWith:'at:')]) ifTrue:[ |
2286 ((sel startsWith:'string:') or:[(sel startsWith:'at:') or:[sel startsWith:'stringWithCRs:']]) ifTrue:[ |
2236 keyStringArgNode := aNode arguments at:1. |
2287 keyStringArgNode := aNode arguments at:1. |
2237 keyStringArgNode isLiteral ifTrue:[ |
2288 keyStringArgNode isLiteral ifTrue:[ |
2238 keyStringArg := keyStringArgNode value. |
2289 keyStringArg := keyStringArgNode value. |
2239 keyStringArg isString ifTrue:[ |
2290 keyStringArg isString ifTrue:[ |
2240 resourceKeys add:keyStringArg. |
2291 resourceKeys add:keyStringArg. |
2241 ] ifFalse:[ |
2292 ] ifFalse:[ |
2242 Transcript |
2293 Transcript |
2243 showCR:(resources |
2294 showCR:(resources |
2244 string:'Cannot derive resourceKey from non-string: %1 in %2' |
2295 string:'Cannot derive resourceKey from non-string: %1 in %2' |
2245 with:keyStringArgNode formattedCode |
2296 with:keyStringArgNode formattedCode |
2246 with:aMethod selector). |
2297 with:aMethod selector). |
2247 ]. |
2298 ]. |
2248 ] ifFalse:[ |
2299 ] ifFalse:[ |
2249 Transcript |
2300 Transcript |
2250 showCR:(resources |
2301 showCR:(resources |
2251 string:'Cannot derive resourceKey from non-literal: %1 in %2' |
2302 string:'Cannot derive resourceKey from non-literal: %1 in %2' |
2252 with:keyStringArgNode formattedCode |
2303 with:keyStringArgNode formattedCode |
2253 with:aMethod selector). |
2304 with:aMethod selector). |
2254 ]. |
2305 ]. |
2255 ]. |
2306 ]. |
2256 aNode |
2307 aNode |
2257 ]. |
2308 ]. |
2258 |
2309 |
2259 matcher executeTree: parseTree initialAnswer: nil. |
2310 matcher executeTree: parseTree initialAnswer: nil. |
2260 ^ resourceKeys |
2311 ^ resourceKeys |
|
2312 |
|
2313 "Modified: / 19-02-2015 / 11:42:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2261 ! |
2314 ! |
2262 |
2315 |
2263 extractTranslationsFromSpecMethod:aMethod |
2316 extractTranslationsFromSpecMethod:aMethod |
2264 ^ #() |
2317 ^ #() |
2265 ! |
2318 ! |