[Nitro] Localization

Michael Fellinger m.fellinger at gmail.com
Sat Feb 18 02:46:47 EST 2006

Hey List,
I've been playing around with localization now for a while and noticedsome, well, a bit annoying problems.First of all, Localization is not in the default-pipeline. I know thisdecision was made a while ago and just want to confirm that this isreally what everyone wants.IMHO localization is one of the important things every moderatly largeproject needs, although most of the nitro-pages are stillenglish-only, it might be a nice addition to all of them to have it athand when you need it.Well, i don't want to clutter the pipeline, but mine looks atm like that:
Compiler.setup_template_transform do |template|  template = StaticInclude.transform(template)  template = Morphing.transform(template, self)  template = Elements.transform(template, self)  template = Markup.transform(template)  template = ScriptCompiler.transform(template, self)  template = Localization.transform(template)  template = Cleanup.transform(template)  template = Template.transform(template)end
all of that only to get localization running... and everytime thedefault-pipline changes i have to reflect all the changes in here,making upgrades a bit tiresome...How large would be the overhead of having the localization in the default?
Well, another thing is, i have made a nice little interface to updatethe localization on the fly, while the application is running. I addedthe controller and template below.My question is, could we integrate this one in the part/admin to beused only when the localization is included? i'm not sure how to checkfor that, so i would like to ask someone to give me a hint on that andif it is wanted at all - at least it's making the whole localization abit less tiresome - imagine having to restart the server all the timeto only change a word :)oh, and if you take a closer look at the template, it's a bit weirdbut the only way i could make this work...
thx in prev~~~~manveru
###### controller.rb::edit_locales ######
  def edit_locales    if request.post?      langs = {}      $languages.each{|l| langs.merge!({l[0] => {}})}      arr = Array.new(request.params.size/$languages.size){{}}      request.params.each{|param|        key = param[0].split('_')        if key[1] == 'key' && !param[1].nil?          $languages.each{|l|            langs[l[0]].merge!({param[1] =>request.params["#{key[0]}_#{l[0]}"]})          }        end      }      Glue::Localization.add(langs)      langs.each_pair{|lang, vals|        File.open("conf/#{lang}_locales.yaml", "w") {|fd|          fd.write(YAML::dump(vals))        }      }    end    redirect_to_referer  end
###### localization.xhtml ######<Page><?rheader = ['Key']+$languages.map{|x| x[1]}locales = @lc.map{|lc| lc }.sorti = 0?><form action="edit_locales" method="post"><table><tr>  <?r for head in header do ?>    <td>#{head}</td>  <?r end ?></tr><?r for row in locales do ?>  <tr>    <td><input name="#{i}_key" type="text" value="#{row[0]}"/></td>    <?r for lang in $languages do ?>      <td>        <textarea name="#{i}_#{lang[0]}" rows="3"cols="40">#{Glue::Localization.get(lang[0])[row[0]]}</textarea>      </td>    <?r end ?>  </tr><?r i+=1; end ?><tr><td><input type="text" name="#{i}_key"/></td>  <?r for lang in $languages do ?>    <td><textarea name="#{i}_#{lang[0]}" rows="3" cols="40"></textarea></td>  <?r end ?></tr><tr><td colspan="#{$languages.size+1}"><input style="width:100%;"type="submit" value="[[save locales]]"/></td></tr></table></form></Page>

More information about the Nitro-general mailing list