Closed MichaelHoste closed 2 years ago
If I implement this solution correctly, would you consider merging it?
Sure.
I think that we should do this in TextDomainManager
not TextDomain
.
I haven't tried it but this may work:
diff --git a/lib/gettext/text_domain_manager.rb b/lib/gettext/text_domain_manager.rb
index e329fb4..c4ced0c 100644
--- a/lib/gettext/text_domain_manager.rb
+++ b/lib/gettext/text_domain_manager.rb
@@ -77,11 +77,12 @@ module GetText
end
def each_text_domains(klass) #:nodoc:
- lang = Locale.candidates[0]
- ClassInfo.related_classes(klass, @@gettext_classes).each do |target|
- if group = @@text_domain_group_pool[target]
- group.text_domains.each do |text_domain|
- yield text_domain, lang
+ Locale.candidates.each do |lang|
+ ClassInfo.related_classes(klass, @@gettext_classes).each do |target|
+ if group = @@text_domain_group_pool[target]
+ group.text_domains.each do |text_domain|
+ yield text_domain, lang
+ end
end
end
end
Thanks a lot for your suggestion @kou !
I'll create a new PR for this in the following weeks with some tests.
I finally created the PR here: #90
The suggested implementation worked great!
The PR was merged and released, I guess we can close this issue now.
I was wondering if GetText has already some existing mechanism to deal with locale fallbacks.
It would be really useful for regional languages (like
en_US
) so we could avoid duplicating, and co-evolving, most translations that are the same.In a project where
fr
is the source language anden
anden_US
are the target languages, it would be nice if a missing translation toen_US
would fallback toen
before fallbacking tofr
(current behaviour).I did a quick ugly hack in
text_domain.rb
(translate_singular_message
) and it seems to work well for me:I replaced
by
If I implement this solution correctly, would you consider merging it @kou ? Or are there any existing alternative?