Loomio
Wed 19 Dec 2018 1:28AM

Customising/Replacing application text within Loomio [explained]

RG Robert Guthrie Public Seen by 164
RG

Robert Guthrie Fri 14 Dec 2018 12:32AM

this has the benefit that you'll still be running normal loomio docker images, so you can keep up with developments effortlessly

J

J Thu 13 Dec 2018 3:24AM

Hi @robertguthrie ! I hope this is an acceptable question...

If I want to customize the names of the proposal options in my own instance, is it really as simple as changing the names in the /config/poll_templates.yml file and then a few extraneous places in the frontend code I found?

https://github.com/loomio/loomio/blob/d55e13a638ed80a8b60801102a687b3d49eeb9a7/config/poll_templates.yml#L3-L6

I'm not linking the frontend code since I'm just concerned about the fundamental change(s) that would need to be made.

I just want to make sure it is/isn't this easy before I decide to try deploying my own instance.

Thanks in advance!

(I understand things like the mailer, dev examples, icons, localization configs, and API would require additional changes, but I'm not worried about those right now — just the core functionality.)

J

J Sat 15 Dec 2018 6:52AM

So it looks like I have my plugin architecture all set up. I tried to test it out in my development environment but I'm not seeing my "translations" at all.

Is it possible to install plugins in a dev environment without having to go through the whole deploy process first?

RG

Robert Guthrie Thu 13 Dec 2018 9:53PM

Hi @j25 , if you just want to change the words, do it via translations with a plugin.

Here is a gist of me looking at a plugin where do do exactly this but for other text in the app.

https://gist.github.com/robguthrie/9812f00672ae6ff857fc58cfed1af255

RG

Robert Guthrie Sat 15 Dec 2018 6:54AM

In development it should be /plugins/something/foldername

the docker folder is mapped into this structure

RG

Robert Guthrie Thu 13 Dec 2018 9:54PM

So if you follow the loomio-deploy repo instructions, then add those files in your plugins folder, it'll all just work. :fingers_crossed:

J

J Sat 15 Dec 2018 8:49PM

Right! Sorry, I didn't explain well. I have have that architecture already in my development environment (see screenshot). That is not from my own deployed instance. I haven't attempted the deploy steps yet, I have only gone through the development environment set up.

I want to verify the plugin works as expected in my dev environment first. But I am not having any luck seeing my translation plugin when starting up the rails server and doing 'gulp dev'. Everything else works fine for the app though.

I read through the plugins guide you all have provided and looked through many other plugins. As far as I can tell, based on the available documentation, I just need to make sure the plugin is enabled. But I must be missing something, right?

I was trying to figure this out on my own and noticed that there's a plugins.rake file which seems to "install" plugins. Do I need to use that somehow? Do I need to enter 'rake plugins:install'?

So the overarching question I have is, is it possible to create a new plugin and have it be installed/loaded/used right away?


Also, I saw the section about "installing existing plugins" in the plugins guide, but that seemed to only pertain to plugins that are on GitHub, correct? https://github.com/loomio/loomio/tree/master/lib/plugins#installing-existing-plugins-onto-your-instance

RG

Robert Guthrie Sun 16 Dec 2018 6:53PM

The directory structure is still wrong. You need another directory in there when it's in dev.

plugins/custom/bsa_translations/

In docker-production, the plugins on the disk are mapped to /plugins/docker/plugin_name

Other notes:
We don't do the "enabled" thing anymore, but it's ok to still have it.

To test if it's loading the .yml file, make your .yml file invalid with some crazy text - you should see it error on startup.

H

Hugi Ásgeirsson Sun 16 Dec 2018 8:06PM

I've tried doing this, but no luck. If i make the .yml file invalid I get an error on startup, so it seems to be loading. However, I'm not seeing the new text in the group memberships pane. Is this method supposed to use the plugin yml for those fields instead of the fields in client.en.yml? I'm note sure I've understood the use case correctly?

Here is how my setup looks:

deployer@talk:~/loomio-deploy$ ls
certificates  docker-compose.yml  env.save  files   nginx   pgdumps  README.md  SLACK.md
client        env                 faye_env  import  pgdata  plugins  scripts    uploads
deployer@talk:~/loomio-deploy$ ls plugins/talk_translations/
config/     .git/       .gitignore  plugin.rb
deployer@talk:~/loomio-deploy$ cat plugins/talk_translations/plugin.rb
module Plugins
  module TalkTranslations
    class Plugin < Plugins::Base
      setup! :talk_translations do |plugin|
        plugin.enabled = true
        plugin.use_translations 'config/locales', :talk
      end
    end
  end
enddeployer@talk:~/loomio-deploy$ cat plugins/talk_translations/config/locales/talk.en.yml
en:
  memberships_page:
    members: 'Borderlings'
    name_label: 'Name'
    coordinator_label: 'Hippie herder'
    remove_member_label: 'Remove'
    fragment_placeholder: 'Filter Borderlings by name or username...'
    messages:
      remove_member_success: 'Removed {{name}}'
      make_admin_success: '{{name}} is now a hippie herder'
      remove_admin_success: '{{name}} is no longer a hippie herder'
    remove_admin_from_self:
      question: 'Are you sure you no longer want to be a hippie herder?'
J

J Mon 17 Dec 2018 12:06AM

I tried moving the plugin to plugins/custom/bsa_translations/ and still no luck :-/

But the good news is it appears that my plugin is being installed, including its translations. I figured out how to check the Plugins::Repository 'repository' class value and my plugin, including its translations, are showing up there.

:bsa_translations=>
#<Plugins::BsaTranslations::Plugin:0x00007fc8b54b1268
@actions=#<Set: {}>,
@assets=#<Set: {}>,
@config={},
@enabled=true,
@events=#<Set: {}>,
@extensions=#<Set: {}>,
@installed=true,
@name=:bsa_translations,
@outlets=#<Set: {}>,
@root="~/Projects/loomio/plugins/custom/bsa_translations",
@routes=#<Set: {}>,
@static_assets=#<Set: {}>,
@translations=
{"en"=>
{"poll_proposal_options"=>
{"agree"=>"Full Support",
"agree_verb"=>"supported",
"agree_meaning"=>
"Used when the voting member completely supports the proposal. This is an approval vote.",
...etc.

@robertguthrie can you explain or point to the code that dictates which translations (e.g. client.en.yml vs. bsa.en.yml) are used? The below code makes it seem like the core_translations come before the plugin_translations.

def as_json
    @json ||= base.deep_merge(core_translations).deep_merge(plugin_translations)
  end

https://github.com/loomio/loomio/blob/master/app/services/client_translation_service.rb

Does that mean client.*.yml files take precedence over #{plugin_name}.*.yml files? If not, how are the plugin .yml files given priority over client .yml files?

I've seen plenty of code about how locales are chosen and whatnot, but not much on how plugin vs. core/client translations are chosen over each other.

Load More