Charles.Forsyth20060303-partialeea662d19 years agoHistory
135 lines · 3.1 KB · Text
RawDownload
.TH TRANSLATE 2.SH NAMEtranslate: opendict, opendicts, mkdictname \- translation dictionaries.SH SYNOPSIS.EXinclude "translate.m";translate := load Translate Translate->PATH; Dict: adt {    new:    fn(): ref Dict;    add:    fn(d: self ref Dict, file: string): string;    xlate:  fn(d: self ref Dict, s: string): string;    xlaten: fn(d: self ref Dict, s: string, note: string): string;}; init:       fn();opendict:   fn(file: string): (ref Dict, string);opendicts:  fn(files: list of string): (ref Dict, string);mkdictname: fn(locale, app: string): string;.EE.SH DESCRIPTIONThe.B Translatemodule provides access to the translation dictionariesdefined by.IR translate (6),intended for the translation oftext from one natural language to another..PP.B Initshould be called before using any of these functions..PP.B Opendictopens a dictionary.I file(of the format defined below) and returns a tuple:a reference to a.B Dictthat represents it and a diagnostic string (which is nil if no error occurred)..B Opendictsis similar, but loads each of the.I filesin turn into the same.BR Dict ,producing a composite dictionary in which translations in later files can overridetranslations in earlier ones;the diagnostic string summarises all errors (if any)..PP.B Mkdictnamereturns the conventional name of a dictionary file givenlocale and application names.The.I localeis normally.B nilto use the current locale, which is formed bybinding the desired locale directory (or directories) onto.BR /lib/locale ..PP.B Dict.newreturns an empty dictionary..B Dict.addloads the given dictionary.I fileinto an existing dictionary, returning a non-nil diagnostic string on error.Translations are made by.B Dict.xlateand.BR Dict.xlaten :they look for a string.I s(eg, text in one language),optionally qualified by a.IR note ,and return the corresponding translation text from the dictionary.If no such translation exists, they return the original text.IR s ..SH EXAMPLEThe following shows one possible style of use:.PP.EX.ta 4n 8n 12n 16n 20ninclude "translate.m";	translate: Translate;	Dict: import translate; dict: ref Dict; X(s: string): string{	if(dict == nil)		return s;	return dict.xlate(s);} init(ctxt: ref Draw->Context, args: list of string){	...	translate = load Translate Translate->PATH;	if(translate != nil){		translate->init();		(dict, nil) = translate->opendict(					translate->mkdictname("", "vmail"));	}	...	optioncfg := array [] of {		"frame .op -relief flat -borderwidth 8",		"frame .op.lbs",		"label .op.lbs.a -text {" +			X("Voice Mail Active") + ":}",		"label .op.lbs.g -text {" +			X("Answer Calls With") + ":}",		"label .op.lbs.r -text {" +			X("Rings before Answering") + ":}",		"label .op.lbs.l -text {" +			X("Length of Incoming Messages") + ":}}",		...	};	...	wmlib->tkcmds(top, optioncfg);}.EE.PPThe intermediate function.B Xis defined to allow the program to be used (albeit with text in English) evenwhen the.B Translatemodule cannot be loaded..SH FILES.BI /locale/ locale /dict/ app.SH SOURCE.B /appl/lib/translate.b.SH SEE ALSO.IR translate (6)