b655bf2004-06-30Martin Stjernholm // The translation module. Copyright © 2000 - 2004, Roxen IS.
afcffc2000-07-09Martin Nilsson // #include <module.h> inherit "module"; // ---------------- Module registration stuff ----------------
b3281f2000-09-10Martin Nilsson constant module_type = MODULE_TAG;
bc0fa02001-03-08Per Hedbor constant module_name = "Tags: Translation module";
afcffc2000-07-09Martin Nilsson constant module_doc = "This module provides an RXML API to the Pike localization system.";
ea0a982000-07-17Andreas Lange constant thread_safe = 1;
b655bf2004-06-30Martin Stjernholm constant cvs_version = "$Id: translation_mod.pike,v 1.14 2004/06/30 16:59:27 mast Exp $";
ea0a982000-07-17Andreas Lange 
afcffc2000-07-09Martin Nilsson  // ------------------------ The tags ------------------------- class TagTranslationRegistration { inherit RXML.Tag; constant name = "trans-reg";
1b2d742001-10-08Anders Johansson  constant flags = RXML.FLAG_EMPTY_ELEMENT;
afcffc2000-07-09Martin Nilsson 
9dda092000-07-21Andreas Lange  mapping(string:RXML.Type) req_arg_types = ([ "project" : RXML.t_text(RXML.PEnt) ]); mapping(string:RXML.Type) opt_arg_types = ([ "path" : RXML.t_text(RXML.PEnt) ]);
afcffc2000-07-09Martin Nilsson  class Frame { inherit RXML.Frame; array do_return(RequestID id) {
b9a7022000-07-15Andreas Lange  if(args->path && args->path!="") { Locale.register_project(args->project, args->path); }
9dda092000-07-21Andreas Lange  id->misc->translation_proj = args->project;
afcffc2000-07-09Martin Nilsson  result = ""; return 0; } } } class TagTranslate { inherit RXML.Tag; constant name = "translate";
9dda092000-07-21Andreas Lange  mapping(string:RXML.Type) opt_arg_types = ([ "id":RXML.t_text(RXML.PEnt), "project":RXML.t_text(RXML.PEnt), "variable":RXML.t_text(RXML.PEnt), "scope":RXML.t_text(RXML.PEnt) ]);
afcffc2000-07-09Martin Nilsson  class Frame { inherit RXML.Frame;
9dda092000-07-21Andreas Lange  array do_return( RequestID id ) {
2de57b2000-07-13Martin Nilsson  string proj = args->project || id->misc->translation_proj;
b9a7022000-07-15Andreas Lange  string trans = Locale.translate(proj, roxen.locale->get(),
9dda092000-07-21Andreas Lange  (int)args->id || args->id,
afcffc2000-07-09Martin Nilsson  content); if(args->variable) { RXML.user_set_var(args->variable, trans, args->scope); return 0; } result = trans; return 0; } } }
9b03652001-03-07Kenneth Johansson TAGDOCUMENTATION; #ifdef manual constant tagdoc=([ "trans-reg":#"<desc tag='tag'><p><short> Registers a locale project in the locale system.</short> Used internally by Roxen. You don't know how to use this tag. </p> </desc> <attr name='project' value='string'><p> The name of the project.</p></attr> <attr name='path' value='string'><p> The path to the projects language files.</p></attr> ", "translate":#"<desc tag='tag'><p><short> Translates the string to an apropriate string in the current locale.</short> Used internally by Roxen. You don't know how to use this tag. </p></desc> <attr name='id' value='string|number'><p> The ID of the string.</p></attr> <attr name='project' value='string'><p> The name of the project in which to look up the string. If only one project is registered on the page the translation tag will default to that project.</p></attr> <attr name='variable' value=''><p> If set, the string will be put in this variable instead of inserted into the current page.</p></attr> <attr name='scope' value=''><p> The scope for the variable.</p></attr> ", ]); #endif