Skip to content

Commit

Permalink
Revert "Switch to v4 alpha of i18n-js (pupilfirst#759)" (pupilfirst#772)
Browse files Browse the repository at this point in the history
This reverts commit f9bd846.
  • Loading branch information
bodhish authored Aug 26, 2021
1 parent f9bd846 commit 7899b5e
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 204 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: Continuous Integration

on:
push:
branches: ["*"]
branches: ['*']
paths-ignore:
- "docs/**"
- 'docs/**'
pull_request:
branches: [master]
branches: [ master ]
paths-ignore:
- "docs/**"
- 'docs/**'

jobs:
tests:
Expand All @@ -32,9 +32,7 @@ jobs:

env:
RAILS_ENV: test
I18N_AVAILABLE_LOCALES: en
I18N_DEFAULT_LOCALE: en
RUBYOPT: "-W:no-deprecated -W:no-experimental"
RUBYOPT: '-W:no-deprecated -W:no-experimental'
JAVASCRIPT_DRIVER: headless_chrome
DB_HOST: localhost
DB_NAME_TEST: postgres
Expand All @@ -54,7 +52,7 @@ jobs:
- name: Use Ruby 2.7
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
ruby-version: '2.7'
- name: Set branch name & commit SHA in env
uses: actions/github-script@v3
with:
Expand Down Expand Up @@ -105,8 +103,6 @@ jobs:
node_modules
app/javascript/packages/*/node_modules
key: ${{ runner.os }}-lerna-${{ hashFiles('**/yarn.lock') }}
- name: Yarn Install
run: yarn install
- name: Precompile Assets
run: |
bundle exec rails assets:precompile
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@ examples.txt
lerna-debug.log

# Ignore test flipper store
flipper.pstore

# Ignore JSON locales generated by i18n-js.
/app/javascript/locales.json
flipper.pstore
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ gem 'pundit', '~> 2.0' # Minimal authorization through OO design and pure Ruby c
gem 'rack-cors', '~> 1.0', require: 'rack/cors' # Rack Middleware for handling CORS, required to serve static assets such as fonts
gem 'graphql', '~> 1.12.6' # Ruby implementation of GraphQL http://graphql-ruby.org
gem 'rodf', '~> 1.1' # ODF generation library for Ruby. https://github.com/westonganger/rodf
gem 'i18n-js', '~> 4.0.0.alpha1' # Provide Rails I18n translations on Javascript.
gem 'i18n-js', '~> 3.7' # Provide Rails I18n translations on Javascript.
gem 'batch-loader', '~> 1.5' # Generic lazy batching mechanism to avoid N+1 DB queries.
gem 'recaptcha', '~> 5.7' # ReCaptcha helpers for Ruby apps. http://github.com/ambethia/recaptcha

Expand Down
8 changes: 3 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ GEM
ruby-progressbar (~> 1.4)
gaffe (1.2.0)
rails (>= 4.0.0)
glob (0.2.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
graphiql-rails (1.7.0)
Expand All @@ -298,9 +297,8 @@ GEM
humanize (2.5.1)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
i18n-js (4.0.0.alpha1)
glob
i18n
i18n-js (3.8.3)
i18n (>= 0.6.6)
ice_nine (0.11.2)
image_processing (1.12.1)
mini_magick (>= 4.9.5, < 5)
Expand Down Expand Up @@ -683,7 +681,7 @@ DEPENDENCIES
graphiql-rails (~> 1.7)
graphql (~> 1.12.6)
humanize (~> 2.1)
i18n-js (~> 4.0.0.alpha1)
i18n-js (~> 3.7)
image_processing (~> 1.12)
jbuilder (~> 2.6)
jquery-rails (~> 4.3)
Expand Down
14 changes: 8 additions & 6 deletions app/javascript/shared/i18n.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { I18n } from "i18n-js";
import translations from "locales.json";
import I18n from "i18n-js";

export const i18n = new I18n(translations);
i18n.locale = document.documentElement.lang || "en";
i18n.missingTranslationPrefix = "Missing translation: ";
I18n.originalMissingTranslation = I18n.missingTranslation;

global.i18n = i18n;
I18n.missingTranslation = (scope, options) => {
console.error("Missing translation " + scope)
return I18n.originalMissingTranslation(scope, options);
};

global.I18n = I18n;
4 changes: 2 additions & 2 deletions app/javascript/shared/utils/I18n.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type options = {
defaults: array<Js.Dict.t<string>>,
}

@bs.scope("i18n") @bs.val
external translate: (string, Js.t<'a>) => string = "t"
@bs.scope("I18n") @bs.val
external translate: (string, Js.t<'a>) => string = "translate"

external optionsToJsObject: options => Js.t<'a> = "%identity"
external variablesToJsObject: Js.Dict.t<string> => Js.t<'a> = "%identity"
Expand Down
113 changes: 51 additions & 62 deletions app/views/layouts/tailwind.html.erb
Original file line number Diff line number Diff line change
@@ -1,76 +1,65 @@
<% presenter = ::Layouts::TailwindPresenter.new(self) %>

<!DOCTYPE html>
<html
lang="<%= I18n.locale %>"
data-user-id="<%= current_user&.id %>"
data-flash="<%= presenter.flash_messages %>"
data-env="<%= Rails.env %>"
data-vapid-public-key="<%= presenter.vapid_public_key_bytes %>"
data-subscription-endpoint="<%= presenter.webpush_subscription_endpoint %>"
>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="manifest" href="/manifest.json" />
<html lang='en' data-user-id="<%= current_user&.id %>" data-flash="<%= presenter.flash_messages %>" data-env="<%= Rails.env %>" data-vapid-public-key="<%= presenter.vapid_public_key_bytes %>" data-subscription-endpoint="<%= presenter.webpush_subscription_endpoint %>">

<% if content_for?(:viewport) %>
<%= yield :viewport %>
<% else %>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<% end %>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="manifest" href="/manifest.json">

<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags. -->
<meta name="theme-color" content="#4D1E9A" />
<%= yield :head %>
<% if content_for?(:viewport) %>
<%= yield :viewport %>
<% else %>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<% end %>

<!-- Styles -->
<link
href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<%= stylesheet_pack_tag 'layouts/tailwind', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'IconFirstPack', media: 'all' %>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags. -->
<meta name="theme-color" content="#4D1E9A">
<%= yield :head %>

<!-- Scripts -->
<%= javascript_pack_tag 'layouts/tailwind', nonce: true %>
<!-- Styles -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<%= stylesheet_pack_tag 'layouts/tailwind', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'IconFirstPack', media: 'all' %>

<%= javascript_tag(nonce: true) do %>
i18n.defaultLocale = "<%= I18n.default_locale %>"; i18n.locale = "<%= I18n.locale %>";
<% end %>
<!-- Scripts -->
<%= javascript_pack_tag 'layouts/tailwind', nonce: true %>

<%= csrf_meta_tags %>
<%= javascript_tag(nonce: true) do %>
I18n.defaultLocale = "<%= I18n.default_locale %>";
I18n.locale = "<%= I18n.locale %>";
<% end %>

<% if presenter.meta_description.present? %>
<meta name="description" content="<%= presenter.meta_description %>" />
<meta
property="og:description"
content="<%= presenter.meta_description %>"
/>
<% end %>
<%= javascript_pack_tag "translations/#{I18n.locale}", nonce: true %>

<%= csrf_meta_tags %>

<link rel="icon" href="/favicon.ico" />
</head>
<% if presenter.meta_description.present? %>
<meta name="description" content="<%= presenter.meta_description %>"/>
<meta property="og:description" content="<%= presenter.meta_description %>"/>
<% end %>

<link rel="icon" href="/favicon.ico"/>
</head>

<body data-host="<%= current_host %>">
<section class="min-h-full flex flex-col items-stretch">
<%= yield :nav %>
<main class="flex-grow bg-gray-100">
<% if content_for?(:wrapper) %>
<%= yield :wrapper %>
<% else %>
<%= yield %>
<% end %>
</main>

<body data-host="<%= current_host %>">
<section class="min-h-full flex flex-col items-stretch">
<%= yield :nav %>
<main class="flex-grow bg-gray-100">
<% if content_for?(:wrapper) %>
<%= yield :wrapper %>
<% else %>
<%= yield %>
<% end %>
</main>
<%= yield :tail %>
<%= yield :footer %>
</section>
<!-- Scripts -->
<%= javascript_pack_tag 'IconFirstPack', nonce: true %>
</body>

<%= yield :tail %>
<%= yield :footer %>
</section>
<!-- Scripts -->
<%= javascript_pack_tag 'IconFirstPack', nonce: true %>
</body>
</html>
4 changes: 2 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

module Pupilfirst
class Application < Rails::Application
VERSION = '2021.4'
VERSION = '2021.3'

# Initialize configuration defaults for originally generated Rails version.
#
Expand Down Expand Up @@ -48,4 +48,4 @@ class Application < Rails::Application

Flipper.configure do |config|
config.adapter { Flipper::Adapters::ActiveRecord.new }
end
end
6 changes: 0 additions & 6 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@
# Raises error for missing translations
# config.i18n.raise_on_missing_translations = true

config.after_initialize do
require 'i18n-js/listen'

I18nJS.listen
end

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

Expand Down
4 changes: 1 addition & 3 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

config.after_initialize { I18nJS.call(config_file: 'config/i18n.yml') }
end

require 'flipper/adapters/pstore'
Flipper.configure do |config|
config.adapter { Flipper::Adapters::PStore.new('flipper.pstore', true) }
end
end
6 changes: 0 additions & 6 deletions config/i18n.yml

This file was deleted.

10 changes: 0 additions & 10 deletions config/initializers/i18n.rb

This file was deleted.

50 changes: 22 additions & 28 deletions config/locales/devise.en.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
# Additional translations at https://github.com/heartcombo/devise/wiki/I18n
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n

en:
devise:
confirmations:
confirmed: "Your email address has been successfully confirmed."
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
confirmed: "Your account was successfully confirmed."
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
failure:
already_authenticated: "You are already signed in."
inactive: "Your account is not activated yet."
invalid: "Invalid %{authentication_keys} or password."
invalid: "Invalid email or password."
locked: "Your account is locked."
last_attempt: "You have one more attempt before your account is locked."
not_found_in_database: "Invalid %{authentication_keys} or password."
last_attempt: "You have one more attempt before your account will be locked."
not_found_in_database: "Invalid email or password."
timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "Please sign in to continue."
unconfirmed: "You have to confirm your email address before continuing."
unconfirmed: "You have to confirm your account before continuing."
mailer:
confirmation_instructions:
subject: "Confirmation instructions"
reset_password_instructions:
subject: "Reset password instructions"
unlock_instructions:
subject: "Unlock instructions"
email_changed:
subject: "Email Changed"
password_change:
subject: "Password Changed"
subject: "Unlock Instructions"
omniauth_callbacks:
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
passwords:
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
send_instructions: "You will receive an email with instructions on how to reset your password."
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
updated: "Your password has been changed successfully. You are now signed in."
updated_not_active: "Your password has been changed successfully."
updated: "Your password was changed successfully. You are now signed in."
updated_not_active: "Your password was changed successfully."
registrations:
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
signed_up: "Welcome! You have signed up successfully."
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
updated: "Your account has been updated successfully."
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again."
destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
signed_up: "Welcome! You have joined us successfully."
signed_up_but_inactive: "You have joined us successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_locked: "You have joined us successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
updated: "You updated your account successfully."
sessions:
signed_in: ""
signed_out: ""
already_signed_out: ""
unlocks:
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
errors:
messages:
Expand Down
Loading

0 comments on commit 7899b5e

Please sign in to comment.