I18n fallback not working


(Oleander) #1

I’m currently having problems with translations not falling back to english if not existing.

I’ve added I18n.fallbacks = true; to app/assets/javascripts/locales/i18n.js,
and config.i18n.fallbacks = true to config/application.rb

My default lang is sv and I’m using the master branch of discourse.

Why isn’t the fallback working?


(Régis Hanol) #2

Are you running the latest version of Discourse? Is it in development or production mode?


(Oleander) #3

Yes, I’m using the master branch on Github in production.


(Joe Taber) #4

Your current branch is not related to whether you’re running in development or production mode.

Also, the key that it’s looking for, user.unread_message_count, is not present in the client.sv.yml file like in english. In fact it looks like a lot of things are missing…


(Oleander) #5

I think you missed my point.

I said I’m running the lasted version of discourse (from the master branch) and I’m seeing this problem in production.

And yes I know that the key is missing. That wasn’t my question. I was asking why the fallback isn’t working. It should display the english version if the swedish doesn’t exist.


(Jeff Atwood) #6

I don’t think that is the way it is designed to work, it displays the key if the translation is missing, not the English. Right @zogstrip?


(Oleander) #7

I just tried using config.i18n.fallbacks = { :sv => :en }, which works in the console, but not in the view. Accessing a non existing key in sv will cause a fallback into en.


(Régis Hanol) #8

On the client-side, we do not support standard rails fallback behavior. As @codinghorror said, we’ll display the key if a translation is missing.

On the server-side, the standard rails behavior is unchanged. That’s why it’s working in the console.

Note: we’ll automatically fallback to the en translation whenever a translation is missing interpolation arguments to avoid bugs in background processes.


(Oleander) #9

I ended up merging client.en.yml with client.sv.yml using this code.

require "deep_merge"
task :merge_yaml do
  slave = YAML.load_file("config/locales/client.sv.yml")["sv"]
  master = YAML.load_file("config/locales/client.en.yml")["en"]
  result = {
    "sv" => master.deep_merge(slave)
  }.to_yaml

  puts result
end

(Loïc) #10

I have a bug that seems related to this one. When sidekiq has to send notification email it fails because : Job exception: translation missing: fr.time.formats.short_no_year

I checked and indeed there is no short_no_year key (no time even) for the french translation. But it seems that I18n fallback is not working as it should here.


(Sam Saffron) #11

@zogstrip we really need to put all issues with fallback not working to rest.


(Régis Hanol) #12

Translation fallback issues should be a thing of the past :ghost:


Editing plugin translation strings in the admin panel when the forum language is not defined for the plugin has no effect
Custom Wizard Plugin
Custom Wizard Plugin
(Régis Hanol) #13