noosfero | 4 new commits pushed to repository

Antonio Terceiro gitlab at gitlab.com
Tue Jan 27 15:36:18 BRST 2015


Antonio Terceiro pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/da3b4c3f71f0197b50524e2a617b547087251c67">da3b4c3f</a> by Larissa Reis
Adds support for domain specific custom locales

  Support for custom locales for hosted environments using the
  multitenancy support and noosfero domains. Some environments need
  personalized translations and this hopefully offers a clean way to do
  it based on domains as well.

  Related to MR 195

(ActionItem3113)

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/ece6c5630ff06d35f466c7fc0cdbb2296a23c587">ece6c563</a> by Larissa Reis
Documentation for custom locales

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/b6108f3c8d9033375aaa5c5fce0d71bc839dad21">b6108f3c</a> by Larissa Reis
Moves custom_locales to config/custom_locales

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/342be5f0702f4f297b2a4894ad51fba1452328a3">342be5f0</a> by Antonio Terceiro
Merge branch 'patch-custom-locales' into 'master'

Custom locales for personalized internationalization

Support for custom locales for hosted environments using the
multitenancy support and noosfero domains. There was a previous
commit for custom locales based on environment (see AI3113 and MR195),
but we also need it to work with a multitenancy system.

See merge request !376

- - - - -


Changes:

=====================================
INSTALL.locales.md
=====================================
--- /dev/null
+++ b/INSTALL.locales.md
@@ -0,0 +1,29 @@
+Using custom locales
+====================
+
+Personalized translations go into the `config/custom_locales/` directory.
+Custom locales can be identified by the rails environment, schema name in a
+multitenancy setup or domain name until the first dot (e.g env1.coop.br for the
+example below).
+
+Currently, the only filename prefix for the localization file which is
+processed is "environment". For instance, a POT file would be called
+"environment.pot".
+
+The structure of an environment named env1 with custom translations for both
+Portuguese and Spanish and an environment named env2 with custom Russian
+translation would be:
+
+    config/
+      custom_locales/
+        env1/
+          environment.pot
+          pt/
+            environment.po
+          es/
+            environment.po
+        env2/
+          environment.pot
+          ru/
+            environment.po
+

=====================================
app/controllers/application_controller.rb
=====================================
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -127,6 +127,9 @@ class ApplicationController < ActionController::Base
 
   # TODO: move this logic somewhere else (Domain class?)
   def detect_stuff_by_domain
+    # Sets text domain based on request host for custom internationalization
+    FastGettext.text_domain = Domain.custom_locale(request.host)
+
     @domain = Domain.find_by_name(request.host)
     if @domain.nil?
       @environment = Environment.default

=====================================
app/models/domain.rb
=====================================
--- a/app/models/domain.rb
+++ b/app/models/domain.rb
@@ -92,4 +92,11 @@ class Domain < ActiveRecord::Base
     @hosting = {}
   end
 
+  # Detects a domain's custom text domain chain if available based on a domain
+  # served on multitenancy configuration or a registered domain.
+  def self.custom_locale(domainname)
+    domain = Noosfero::MultiTenancy.mapping[domainname] || domainname[/(.*?)\./,1]
+    FastGettext.translation_repositories.keys.include?(domain) ? domain : FastGettext.default_text_domain
+  end
+
 end

=====================================
lib/noosfero/i18n.rb
=====================================
--- a/lib/noosfero/i18n.rb
+++ b/lib/noosfero/i18n.rb
@@ -9,7 +9,8 @@ class Object
 end
 
 
-custom_locale_dir = Rails.root.join('custom_locales', Rails.env)
+# Adds custom locales for a whole environment
+custom_locale_dir = Rails.root.join('config', 'custom_locales', Rails.env)
 repos = []
 if File.exists?(custom_locale_dir)
   repos << FastGettext::TranslationRepository.build('environment', :type => 'po', :path => custom_locale_dir)
@@ -29,3 +30,15 @@ end
 
 FastGettext.add_text_domain 'noosfero', :type => :chain, :chain => repos
 FastGettext.default_text_domain = 'noosfero'
+
+# Adds custom locales for specific domains; Domains are identified by the
+# sequence before the first dot, while tenants are identified by schema name
+hosted_environments = Noosfero::MultiTenancy.mapping.values
+hosted_environments += Domain.all.map { |domain| domain.name[/(.*?)\./,1] } if Domain.table_exists?
+
+hosted_environments.uniq.each do |env|
+  custom_locale_dir = Rails.root.join('config', 'custom_locales', env)
+  if File.exists?(custom_locale_dir)
+    FastGettext.add_text_domain(env, :type => :chain, :chain => [FastGettext::TranslationRepository.build('environment', :type => 'po', :path => custom_locale_dir)] + repos)
+  end
+end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150127/391d6d31/attachment.html>


More information about the Noosfero-dev mailing list