'From Squeak3.1alpha of 28 February 2001 [latest update: #4358] on 1 October 2001 at 10:33:04 am'! "Change Set: translSmooth-sw Date: 1 Oct 2001 Author: Scott Wallace Smooths out the mechanism for adding new natural-language translations of standard vocabularies -- less hard-coding, more self-configuring. A class-variable in Vocabulary holds on to the available-language list, so adding new languages can be done dynamically without needing to modify any base system methods. If you add a new natural language and you want it to be available in the 'set language' menu, have your file-in do a do-it of the following form, substituting your language name for XX: Vocabulary setTranslationInitializer: #addXXVocabulary forLanguageSymbol: #XX "! ObjectWithDocumentation subclass: #Vocabulary instanceVariableNames: 'vocabularyName categories methodInterfaces object limitClass translationTable ' classVariableNames: 'AllStandardVocabularies LanguageSymbols LanguageTable ' poolDictionaries: '' category: 'Protocols-Kernel'! !Project methodsFor: 'language' stamp: 'sw 9/14/2001 10:26'! chooseNaturalLanguage "Put up a menu allowing the user to choose the natural language for the project" | aMenu | aMenu _ MenuMorph new defaultTarget: self. aMenu addTitle: 'choose language'. aMenu lastItem setBalloonText: 'This controls the human language in which tiles should be viewed. It is potentially extensible to be a true localization mechanism, but initially it only works in the classic tile scripting system. Each project has its own private language choice'. aMenu addStayUpItem. Vocabulary languageSymbols do: [:langSymbol | aMenu addUpdating: #stringForLanguageNameIs: target: self selector: #setNaturalLanguageTo: argumentList: {langSymbol}]. aMenu popUpInWorld "Project current chooseNaturalLanguage"! ! !EToyVocabulary methodsFor: 'language translations' stamp: 'sw 9/14/2001 10:54'! addEnglishVocabulary "A no-op since the english version of the etoy vocabulary is intrinsic"! ! !EToyVocabulary methodsFor: 'language translations' stamp: 'sw 9/14/2001 10:52'! assureTranslationsAvailableFor: aLanguageSymbol "Any vocabulary that has translations for the language gets this called when language switches " | initializer | initializer _ Vocabulary initializerForLanguageSymbol: aLanguageSymbol. initializer ifNotNil: [self perform: initializer].! ! !Vocabulary class methodsFor: 'class initialization' stamp: 'sw 10/1/2001 10:31'! initializeLanguageTable "Initialize the default set of natural langauges. Others can be added dynamically by sending #setTranslationInitializ:forLanguageSymbol:" LanguageTable _ Dictionary new. #( (English addEnglishVocabulary) (Deutsch addGermanVocabulary) (Kiswahili addKiswahiliVocabulary)) do: [:pair | LanguageTable at: pair first put: pair second]. "Vocabulary initializeLanguageTable"! ! !Vocabulary class methodsFor: 'class initialization' stamp: 'sw 10/1/2001 09:44'! initializerForLanguageSymbol: natLangSymbol "Answer the name of the Vocabulary method to call in order to initialize the translations for the given natural-language symbol" LanguageTable ifNil: [self initializeLanguageTable]. ^ LanguageTable at: natLangSymbol ifAbsent: [nil] " Vocabulary initializerForLanguageSymbol: #Deutsch Vocabulary initializerForLanguageSymbol: #Elmer "! ! !Vocabulary class methodsFor: 'class initialization' stamp: 'sw 10/1/2001 10:28'! languageSymbols "Answer the language symbols currently known to the vocabulary system. The informtion is held in the LanguageTable, which can be dynamically added to by calling #setTranslationInitializer:forLanguageSymbol:" LanguageTable ifNil: [self initializeLanguageTable]. ^ LanguageTable keys asSortedArray "Vocabulary languageSymbols"! ! !Vocabulary class methodsFor: 'class initialization' stamp: 'sw 10/1/2001 10:32'! setTranslationInitializer: aSelector forLanguageSymbol: aLanguageSymbol "Make a note of the availability of a language, and of the name of the method that would be invoked to do the actual translation into the language. This method typically has no senders in an image, but rather is intended to be called by do-its in the preambles or postscripts of updates, etc." LanguageTable ifNil: [self initializeLanguageTable]. LanguageTable at: aLanguageSymbol put: aSelector "Vocabulary setTranslationInitializer: #addSalamanderVocabulary forLanguageSymbol: #Salamander"! !