Use custom translation file


(Aselox) #1

Hello,
I’d like to use my own client.xx.yml and server.xx.yml files for translations but even if I place my files into the config/locales folders replacing the existing ones, I still get the translation included in discourse. I tried to start/stop the docker instance and to bootstrap it making it automatically download my custom files from a git repo (modifying the app.yml file) but the translation is still the same.

What do I have to do to make my translations work?

Thank you.


Changing locales configuration
Discourse in Croatian
Access ssh app files using sftp?
(Neil Lalonde) #2

What does your container yml file look like? Are you copying the files into the config/locales directory in the after_code hook?

hooks:
  after_code:
  - exec:
      cd: $home
      cmd:
      - cp my/i18n/files/client.en.yml /var/www/discourse/config/locales/client.en.yml
      - ...

(Aselox) #3

@neil this is the hooks section from my container/app.yml file:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
        cd: $home/config/locales
        cmd:
          - git clone https://Aselox@bitbucket.org/Aselox/discourse-locale.git

And the wanted locale files are into the locales folder but the website seems to be using the old one. I honestly don’t know where it reads them from.


(Aselox) #4

Anyone? I changed the category to support.


(Kane York) #5

Hmm, based on the code, it should become an available locale once you place the translation files there:

  def self.supported_locales
    @lock.synchronize do
      @supported_locales ||= Dir.glob( File.join(Rails.root, 'config', 'locales', 'client.*.yml') ).map {|x| x.split('.')[-2]}.sort
    end
  end

If you type Discourse.SiteSettings.available_locales in the javascript console, what comes up?


(Aselox) #6

The language appears in the languages dropdown, the problem is that even if I modify the files in /config/locales, Discourse keeps using the original locales files like if I didn’t modify them at all. I don’t know if it’s something like a cache (not a browser cache) or I’m doing something wrong.

UPDATE: I think I found the problem. I had to do ./launcher destroy app


(Aselox) #7

Ok, so… With the ./launcher destroy app command Discourse started using the updated translation on github but my custom files are still like ghosts for it.


(Kai) #8

Please ssh into the container, cd into config/locales. Is there a subdir called discourse-locale? Please place the files directly under config/locales instead. This works for me:

hooks:
  after_code:
        cd: /tmp
        cmd:
          - rm -rf discourse-locales
          - git clone https://github.com/kschaper/discourse-locales.git
          - mv discourse-locales/*.yml $home/config/locales/

The best way for moderators/admins to override particular strings
(Anton) #9

Any update on this?
I also need a custom translation file to be used.

@Aselox, could you please share a bit more info about what file exactly do you clone and translate, and do you only track those 2 particular files in your git repo?

Can anyone share a 1,2,3 guide for this that’s proven and works, please?


(Marcin Rataj) #10

@meglio if it is still relevant to you, check my solution: discourse-locale-override. It is reusable with other languages and should cover your needs.


(Anton) #11

Thanks. Should my YML files contain only overriden strings?


(Marcin Rataj) #12

It overrides original locale files, so the new files must have all strings.


The best way to edit Markdown.Editor.js?
#14

I saw your override hack. I have a question for you. (non-programmer’s :smile: )

This is my container/app.yml (very default version of Discourse. I just installed it)

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git

To use your override, what is the correct yml file look?

A. Add from cd: /tmp

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
        cd: /tmp
        cmd:
          - git clone https://github.com/lidel/discourse-locale-override.git
          - mv discourse-locale-override/*.yml $home/config/locales/
          - mv discourse-locale-override/plugins/emoji/*.yml $home/plugins/emoji/config/locales/
          - mv discourse-locale-override/plugins/poll/*.yml $home/plugins/poll/config/locales/
          - rm -rf discourse-locale-override

B. Keep above default codes, and just add your entire codes

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git

hooks:
  after_code:
    - exec:
        cd: /tmp
        cmd:
          - git clone https://github.com/lidel/discourse-locale-override.git
          - mv discourse-locale-override/*.yml $home/config/locales/
          - mv discourse-locale-override/plugins/emoji/*.yml $home/plugins/emoji/config/locales/
          - mv discourse-locale-override/plugins/poll/*.yml $home/plugins/poll/config/locales/
          - rm -rf discourse-locale-override

(Marcin Rataj) #15

I think A should work. I have a separate exec: section just for clarity.
Config of my instance looks like this:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-spoiler-alert.git
          - git clone https://github.com/kasperpeulen/discourse-mathjax
    - exec:
        cd: /tmp
        cmd:
          - git clone https://github.com/lidel/discourse-locale-override.git
          - mv discourse-locale-override/*.yml $home/config/locales/
          - mv discourse-locale-override/plugins/emoji/*.yml $home/plugins/emoji/config/locales/
          - mv discourse-locale-override/plugins/poll/*.yml $home/plugins/poll/config/locales/
          - rm -rf discourse-locale-override

Hope this helps!


#16

Thanks a lot!

I will try with the separate exec:


#17

Oops… something went to wrong. :frowning:

I made my container/app.yml as your description,
then I did Rebuild Discourse: /var/discourse/launcher rebuild app

After about 10 minutes? My putty ended with this:

root@ubuntu

[155] 04 Oct 03:32:19.051 * 10 changes in 300 seconds. Saving...
[155] 04 Oct 03:32:19.052 * Background saving started by pid 694
[694] 04 Oct 03:32:19.160 * DB saved on disk
[694] 04 Oct 03:32:19.161 * RDB: 2 MB of memory used by copy-on-write
[155] 04 Oct 03:32:19.253 * Background saving terminated with success

Now, I can’t see my discourse site.
What is wrong?

and I tried to get my discourse back, I changed my app.yml as original.
Then tried /var/discourse/launcher rebuild app but failed with this message:

FAILED
--------------------
RuntimeError: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 ||                       exit 0 && echo postgres already running stop container ; exit 1 failed with ret                      urn #<Process::Status: pid 45 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:85:in `spawn'
exec failed with the params "socat /dev/null UNIX-CONNECT:/shared/postgres_run/.                      s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1"
64930a6f8194f66923609f48a59f8a49c08f0e2069dd00393efb681bc6d1bd5e
FAILED TO BOOTSTRAP

Would you help me please?


(Jeff Atwood) #18

Are you saying you never got a command prompt back on rebuild? Eg it hung on those statements?

If so, reboot and try rebuilding again.


#19

I never got a command prompt back on the first rebuild. It stopped like… 20 minutes?
OK I did reboot.
Now I am rebuilding again with no ‘FAILED TO BOOTSTRAP’ message.

Done. My discourse site restored. (with default app.yml)

I will try @lidel 's override… again, but I have No idea why it stopped before.


#20

I added the override script in app.yml, and did /var/discourse/launcher rebuild app successfully.
(I tried this time with DigitalOcean droplet. I was using discourse with other VPS)

However, in admin panel I selected my own custom locale file (I was happy for a moment),

and then my site got crashed.

Oops… again. Now I cannot see anything.

Cannot rebuild … I face ‘FAILED TO BOOTSTRAP’ message every rebuilding trials.
(even with default app.yml and several reboots)

I found ‘InvailidLocale’ part.
‘my_KO’ was my custom locale that I selected before and site broke.
(My discourse broke because my custom locale is recognized invalid?)

Should I have named my custom locale with exist locale name? such as: client.ko.yml or client.en.yml not client.my_KO.yml? (oh… that’s why ‘override’… :frowning: )
How can I change it with a valid locale manually? (I cannot approach my discourse site at all now.)

I, [2014-10-04T05:58:30.145931 #42]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
rake aborted!
I18n::InvalidLocale: "my_KO" is not a valid locale
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/i18n-0.6.11/lib/i18n.rb:285:in `enforce_available_locales!'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/i18n-0.6.11/lib/i18n/config.rb:11:in `locale='
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/i18n-0.6.11/lib/i18n.rb:35:in `locale='
/var/www/discourse/lib/tasks/db.rake:3:in `block in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I, [2014-10-04T05:58:43.691410 #42]  INFO -- :


FAILED
--------------------
RuntimeError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 259 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:85:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"web", "cmd"=>["gem update bundler", "chown -R discourse $home", "su discourse -c 'bundle install --deployment --verbose --without test --without development'", "su discourse -c 'bundle exec rake db:migrate'", "su discourse -c 'bundle exec rake assets:precompile'"]}
bcfdd3ccb1a10a76c83c87d2b5bbaf9e1b1b388f4eddba77ad53d902d0c1acca
FAILED TO BOOTSTRAP

(Marcin Rataj) #21

Ouch, that never happened to me :scream_cat: Don’t worry tho, it should be easy to fix:

Yup, you should’ve used already existing filename such as client.ko.yml (override).
I guess things broke because there are other files (eg. app/assets/javascripts/locales/ko.js.erb) which we don’t override, but are crucial for correct site translation.

I think you just need to change my_KO (in app.yml and settings in database) to ko and rebuild.

# (update my_KO to ko in app.yml) and then:

ssh localhost -p 2222 'cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails runner "SiteSetting.default_locale = \"ko\""'

/var/discourse/launcher rebuild app