Skip to content

Instantly share code, notes, and snippets.

@naveedshahzad
Last active May 6, 2016 12:34
Show Gist options
  • Save naveedshahzad/6297ed5822b3fc09ef0ee61aa83abb11 to your computer and use it in GitHub Desktop.
Save naveedshahzad/6297ed5822b3fc09ef0ee61aa83abb11 to your computer and use it in GitHub Desktop.
Translate PQtrack
open following url, while you are logged into your github account
https://github.com/ministryofjustice/parliamentary-questions/
Click on Fork button
it will create a copy of the project into your github account.
Clone the project from your github account
git@github.com:naveedshahzad/parliamentary-questions.git
In the above url 'naveedshahzad' is my username and this will be your github username for your fork.
Create a branch by running following command
git checkout -b i18n
Internationalize the code i.e. identify all strings in the code and add those to config/locales/en.yml file. for e.g.
in file app/views/watchlist_members/show.html.slim line #11 is following
= link_to 'Return to watchlist member list', watchlist_members_path, {class: 'admin-link'}
In this line 'Return to watchlist member list' is an english string.
Move it to config/locales/en.yml as following
en:
watchlist_members:
show:
return_to_watchlist_member: Return to watchlist member list
i.e. create a key with view folder name under en, in this case this is 'watchlist_members', then further add a nested key with view file name, in this case 'show', and finally add the suitable key for the string, in this case it is 'return_to_watchlist_member'.
Now change the original line in view file, to call this translation instead of directly referring to string in following way
= link_to t('.return_to_watchlist_member'), watchlist_members_path, {class: 'admin-link'}
Notice 't('.return_to_watchlist_member')' call in above line.
Repeat the above process for every string found in the project.
To translate to spanish
Copy config/locales/en.yml to config/locales/es.yml
##Locale in url
add following methods in app/controllers/application_controller.rb
before_action :set_locale
def default_url_options(options = {})
{ locale: I18n.locale }.merge options
end
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
After making above changes, we will be able to browse our site in translation by passing following parameter in url
www.example.com?locale=es
##Merging changes back to dev branch
git add config/locales/es.yml
git commit -am "i18n branch"
git checkout dev
git merge i18n --no-ff
##Mail Config
Update the config/environments/development.rb file and change the following line
ActionMailer::Base.delivery_method = :sendmail
with
ActionMailer::Base.delivery_method = :smtp
Then to start the rails server, run command with following variables, hostname is for sendgrid
PQ_REST_API_HOST=<Your Live IP OR Domain Name of your server> SENDING_HOST=<Your Live IP OR Domain Name of your server> SMTP_HOSTNAME="smtp.sendgrid.net" SMTP_PORT=587 SMTP_USERNAME=<sendgrid username> SMTP_PASSWORD=<sendgrid password>
And mails would be working
##Synching with https://github.com/ministryofjustice/parliamentary-questions/
git remote add upstream git@github.com/ministryofjustice/parliamentary-questions.git
git fetch upstream
git checkout dev
git rebase upstream/dev
Fix any conflicts if found in the above step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment