commit rubygem-fast_gettext for openSUSE:Factory
Hello community, here is the log from the commit of package rubygem-fast_gettext for openSUSE:Factory checked in at 2017-03-31 15:00:38 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-fast_gettext (Old) and /work/SRC/openSUSE:Factory/.rubygem-fast_gettext.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rubygem-fast_gettext" Fri Mar 31 15:00:38 2017 rev:20 rq:481719 version:1.4.0 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-fast_gettext/rubygem-fast_gettext.changes 2016-11-03 12:57:38.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-fast_gettext.new/rubygem-fast_gettext.changes 2017-03-31 15:00:39.423286731 +0200 @@ -1,0 +2,6 @@ +Sat Mar 18 05:29:57 UTC 2017 - coolo@suse.com + +- updated to version 1.4.0 + see installed CHANGELOG + +------------------------------------------------------------------- Old: ---- fast_gettext-1.3.0.gem New: ---- fast_gettext-1.4.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-fast_gettext.spec ++++++ --- /var/tmp/diff_new_pack.wS8art/_old 2017-03-31 15:00:40.207175919 +0200 +++ /var/tmp/diff_new_pack.wS8art/_new 2017-03-31 15:00:40.207175919 +0200 @@ -1,7 +1,7 @@ # # spec file for package rubygem-fast_gettext # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,7 +24,7 @@ # Name: rubygem-fast_gettext -Version: 1.3.0 +Version: 1.4.0 Release: 0 %define mod_name fast_gettext %define mod_full_name %{mod_name}-%{version} ++++++ fast_gettext-1.3.0.gem -> fast_gettext-1.4.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Readme.md new/Readme.md --- old/Readme.md 2016-10-19 18:48:48.000000000 +0200 +++ new/Readme.md 2017-03-17 21:19:05.000000000 +0100 @@ -44,46 +44,60 @@ ===== ### 1. Install - sudo gem install fast_gettext +```Bash +gem install fast_gettext +``` ### 2. Add a translation repository From mo files (traditional/default) - FastGettext.add_text_domain('my_app', path: 'locale') +```Ruby +FastGettext.add_text_domain('my_app', path: 'locale') +``` Or po files (less maintenance than mo) - FastGettext.add_text_domain('my_app', path: 'locale', type: :po) - # :ignore_fuzzy => true to not use fuzzy translations - # :report_warning => false to hide warnings about obsolete/fuzzy translations +```Ruby +FastGettext.add_text_domain('my_app', path: 'locale', type: :po) +# :ignore_fuzzy => true to not use fuzzy translations +# :report_warning => false to hide warnings about obsolete/fuzzy translations +``` Or yaml files (use I18n syntax/indentation) - FastGettext.add_text_domain('my_app', path: 'config/locales', type: :yaml) +```Ruby +FastGettext.add_text_domain('my_app', path: 'config/locales', type: :yaml) +``` Or database (scaleable, good for many locales/translators) - # db access is cached <-> only first lookup hits the db - require "fast_gettext/translation_repository/db" - FastGettext::TranslationRepository::Db.require_models #load and include default models - FastGettext.add_text_domain('my_app', type: :db, model: TranslationKey) +```Ruby +# db access is cached <-> only first lookup hits the db +require "fast_gettext/translation_repository/db" +FastGettext::TranslationRepository::Db.require_models #load and include default models +FastGettext.add_text_domain('my_app', type: :db, model: TranslationKey) +``` ### 3. Choose text domain and locale for translation Do this once in every Thread. (e.g. Rails -> ApplicationController) - FastGettext.text_domain = 'my_app' - FastGettext.available_locales = ['de','en','fr','en_US','en_UK'] # only allow these locales to be set (optional) - FastGettext.locale = 'de' +```Ruby +FastGettext.text_domain = 'my_app' +FastGettext.available_locales = ['de','en','fr','en_US','en_UK'] # only allow these locales to be set (optional) +FastGettext.locale = 'de' +``` ### 4. Start translating - include FastGettext::Translation - _('Car') == 'Auto' - _('not-found') == 'not-found' - s_('Namespace|not-found') == 'not-found' - n_('Axis','Axis',3) == 'Achsen' #German plural of Axis - _('Hello %{name}!') % {name: "Pete"} == 'Hello Pete!' +```Ruby +include FastGettext::Translation +_('Car') == 'Auto' +_('not-found') == 'not-found' +s_('Namespace|not-found') == 'not-found' +n_('Axis','Axis',3) == 'Achsen' #German plural of Axis +_('Hello %{name}!') % {name: "Pete"} == 'Hello Pete!' +``` Managing translations @@ -93,12 +107,14 @@ Tell Gettext where your .mo or .po files lie, e.g. for locale/de/my_app.po and locale/de/LC_MESSAGES/my_app.mo - FastGettext.add_text_domain('my_app', path: 'locale') +```Ruby +FastGettext.add_text_domain('my_app', path: 'locale') +``` Use the [original GetText](http://github.com/mutoh/gettext) to create and manage po/mo-files. (Work on a po/mo parser & reader that is easier to use has started, contributions welcome @ [get_pomo](http://github.com/grosser/get_pomo) ) -###Database +### Database [Example migration for ActiveRecord](http://github.com/grosser/fast_gettext/blob/master/examples/db/migration.rb)<br/> The default plural seperator is `||||` but you may overwrite it (or suggest a better one..). @@ -115,22 +131,24 @@ Setting `available_locales`,`text_domain` or `locale` will not work inside the `evironment.rb`, since it runs in a different thread then e.g. controllers, so set them inside your application_controller. - #environment.rb after initializers - Object.send(:include, FastGettext::Translation) - FastGettext.add_text_domain('accounting', path: 'locale') - FastGettext.add_text_domain('frontend', path: 'locale') - ... - - #application_controller.rb - class ApplicationController ... - include FastGettext::Translation - before_filter :set_locale - def set_locale - FastGettext.available_locales = ['de','en',...] - FastGettext.text_domain = 'frontend' - FastGettext.set_locale(params[:locale] || session[:locale] || request.env['HTTP_ACCEPT_LANGUAGE']) - session[:locale] = I18n.locale = FastGettext.locale - end +```Ruby +# config/environment.rb after initializers +Object.send(:include, FastGettext::Translation) +FastGettext.add_text_domain('accounting', path: 'locale') +FastGettext.add_text_domain('frontend', path: 'locale') +... + +# app/controllers/application_controller.rb +class ApplicationController ... + include FastGettext::Translation + before_filter :set_locale + def set_locale + FastGettext.available_locales = ['de','en',...] + FastGettext.text_domain = 'frontend' + FastGettext.set_locale(params[:locale] || session[:locale] || request.env['HTTP_ACCEPT_LANGUAGE']) + session[:locale] = I18n.locale = FastGettext.locale + end +``` Advanced features @@ -142,102 +160,132 @@ Via Ruby: - FastGettext.pluralisation_rule = lambda{|count| count > 5 ? 1 : (count > 2 ? 0 : 2)} +```Ruby +FastGettext.pluralisation_rule = lambda{|count| count > 5 ? 1 : (count > 2 ? 0 : 2)} +``` Via mo/pofile: - Plural-Forms: nplurals=2; plural=n==2?3:4; +``` +Plural-Forms: nplurals=2; plural=n==2?3:4; +``` [Plural expressions for all languages](http://translate.sourceforge.net/wiki/l10n/pluralforms). -###default_text_domain +### default_text_domain If you only use one text domain, setting `FastGettext.default_text_domain = 'app'` is sufficient and no more `text_domain=` is needed -###default_locale +### default_locale If the simple rule of "first `availble_locale` or 'en'" is not suficcient for you, set `FastGettext.default_locale = 'de'`. -###default_available_locales +### default_available_locales Fallback when no available_locales are set -###Chains +### with_locale +If there is content from different locales that you wish to display, you should use the with_locale option as below: + +```Ruby +FastGettext.with_locale 'gsw_CH' do + FastGettext._('Car was successfully created.') +end +# => "Z auto isch erfolgriich gspeicharat worda." +``` + +### Chains You can use any number of repositories to find a translation. Simply add them to a chain and when the first cannot translate a given key, the next is asked and so forth. - repos = [ - FastGettext::TranslationRepository.build('new', path: '....'), - FastGettext::TranslationRepository.build('old', path: '....') - ] - FastGettext.add_text_domain 'combined', type: :chain, :chain: repos +```Ruby +repos = [ + FastGettext::TranslationRepository.build('new', path: '....'), + FastGettext::TranslationRepository.build('old', path: '....') +] +FastGettext.add_text_domain 'combined', type: :chain, :chain: repos +``` -###Merge +### Merge In some cases you can benefit from using merge repositories as an alternative to chains. They behave nearly the same. The difference is in the internal data structure. While chain repos iterate over the whole chain for each translation, merge repositories select and store the first translation at the time a subordinate repository is added. This puts the burden on the load phase and speeds up the translations. - repos = [ - FastGettext::TranslationRepository.build('new', :path: '....'), - FastGettext::TranslationRepository.build('old', :path: '....') - ] - domain = FastGettext.add_text_domain 'combined', type: :merge, chain: repos +```Ruby +repos = [ + FastGettext::TranslationRepository.build('new', :path: '....'), + FastGettext::TranslationRepository.build('old', :path: '....') +] +domain = FastGettext.add_text_domain 'combined', type: :merge, chain: repos +``` Downside of this approach is that you have to reload the merge repo each time a language is changed. - FastGettext.locale = 'de' - domain.reload +```Ruby +FastGettext.locale = 'de' +domain.reload +``` -###Logger +### Logger When you want to know which keys could not be translated or were used, add a Logger to a Chain: - repos = [ - FastGettext::TranslationRepository.build('app', path: '....') - FastGettext::TranslationRepository.build('logger', type: :logger, callback: lambda{|key_or_array_of_ids| ... }), - } - FastGettext.add_text_domain 'combined', type: :chain, chain: repos +```Ruby +repos = [ + FastGettext::TranslationRepository.build('app', path: '....') + FastGettext::TranslationRepository.build('logger', type: :logger, callback: lambda{|key_or_array_of_ids| ... }), +} +FastGettext.add_text_domain 'combined', type: :chain, chain: repos +``` If the Logger is in position #1 it will see all translations, if it is in position #2 it will only see the unfound. Unfound may not always mean missing, if you choose not to translate a word because the key is a good translation, it will appear nevertheless. A lambda or anything that responds to `call` will do as callback. A good starting point may be `examples/missing_translations_logger.rb`. -###Plugins +### Plugins Want a xml version ? Write your own TranslationRepository! - #fast_gettext/translation_repository/xxx.rb - module FastGettext - module TranslationRepository - class Wtf - define initialize(name,options), [key], plural(*keys) and - either inherit from TranslationRepository::Base or define available_locales and pluralisation_rule - end - end +```Ruby +# fast_gettext/translation_repository/xxx.rb +module FastGettext + module TranslationRepository + class Wtf + define initialize(name,options), [key], plural(*keys) and + either inherit from TranslationRepository::Base or define available_locales and pluralisation_rule end + end +end +``` -###Multi domain support +### Multi domain support If you have more than one gettext domain, there are two sets of functions available: - include FastGettext::TranslationMultidomain +```Ruby +include FastGettext::TranslationMultidomain - d_("domainname", "string") # finds 'string' in domain domainname - dn_("domainname", "string", "strings", 1) # ditto - # etc. +d_("domainname", "string") # finds 'string' in domain domainname +dn_("domainname", "string", "strings", 1) # ditto +# etc. +``` These are helper methods so you don't need to write: - FastGettext.text_domain = "domainname" - _("string") +```Ruby +FastGettext.text_domain = "domainname" +_("string") +``` It is useful in Rails plugins in the views for example. The second set of functions are D functions which search for string in _all_ domains. If there are multiple translations in different domains, it returns them in random order (depends on the Ruby hash implementation): - include FastGettext::TranslationMultidomain +```Ruby +include FastGettext::TranslationMultidomain - D_("string") # finds 'string' in any domain - # etc. +D_("string") # finds 'string' in any domain +# etc. +``` Alternatively you can use [merge repository](https://github.com/grosser/fast_gettext#merge) to achieve the same behaviour. @@ -274,6 +322,7 @@ - [Lukáš Zapletal](https://github.com/lzap) - [Dominic Cleal](https://github.com/domcleal) - [Tomas Strachota](https://github.com/tstrachota) + - [Martin Meier](https://github.com/mameier) [Michael Grosser](http://grosser.it)<br/> michael@grosser.it<br/> Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/fast_gettext/translation_repository/base.rb new/lib/fast_gettext/translation_repository/base.rb --- old/lib/fast_gettext/translation_repository/base.rb 2016-10-19 18:48:48.000000000 +0200 +++ new/lib/fast_gettext/translation_repository/base.rb 2017-03-17 21:19:05.000000000 +0100 @@ -4,6 +4,9 @@ # - base for all repositories # - fallback as empty repository, that cannot translate anything but does not crash class Base + + attr_reader :name, :options + def initialize(name,options={}) @name = name @options = options diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/fast_gettext/version.rb new/lib/fast_gettext/version.rb --- old/lib/fast_gettext/version.rb 2016-10-19 18:48:48.000000000 +0200 +++ new/lib/fast_gettext/version.rb 2017-03-17 21:19:05.000000000 +0100 @@ -1,3 +1,3 @@ module FastGettext - VERSION = Version = '1.3.0' + VERSION = Version = '1.4.0' end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2016-10-19 18:48:48.000000000 +0200 +++ new/metadata 2017-03-17 21:19:05.000000000 +0100 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: fast_gettext version: !ruby/object:Gem::Version - version: 1.3.0 + version: 1.4.0 platform: ruby authors: - Michael Grosser autorequire: bindir: bin cert_chain: [] -date: 2016-10-19 00:00:00.000000000 Z +date: 2017-03-17 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rake
participants (1)
-
root@hilbert.suse.de