Skip to content

Commit 82ea83d

Browse files
committed
[webpack] fix translation calls in handlebars files
Fixes: CNVS-34067 Test plan: * with webpack turned on and in prod mode * run RAILS_ENV=production bundle exec rake canvas:compile_assets * pick a different language on your user settings page (e.g.maori) * go to /calendar * the “week, Month, Agenda” buttons and everything else on the page should be translated into your language * go to other pages, e.g. /courses/x/assignments/new * all of the strings on those pages should be translated too (The broken behavior was that any strings that came from handlebars Files would not be translated but ones coming from js, erb or Coffeescript were) Change-Id: I9a4b76e857b6c809b663d18abd7196ca10ef8564 Reviewed-on: https://gerrit.instructure.com/102534 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Reviewed-by: Jon Jensen <jon@instructure.com> Product-Review: Ryan Shaw <ryan@instructure.com>
1 parent 89e99cb commit 82ea83d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

frontend_build/i18nLinerHandlebars.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ const {allFingerprintsFor} = require('brandable_css/lib/main')
1212
const PreProcessor = require('./../gems/canvas_i18nliner/node_modules/i18nliner-handlebars/dist/lib/pre_processor')
1313
require('./../gems/canvas_i18nliner/js/scoped_hbs_pre_processor')
1414

15+
// In this main file, we do a bunch of stuff to monkey-patch the default behavior of
16+
// i18nliner's HbsProcessor (specifically, we set the the `directories` and define a
17+
// `normalizePath` function so that translation keys stay relative to canvas root dir).
18+
// By requiring it here the code here will use that monkeypatched behavior.
19+
require('../gems/canvas_i18nliner/js/main')
20+
1521
const compileHandlebars = (data) => {
1622
const path = data.path
1723
const source = data.source

gems/canvas_i18nliner/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var ScopedTranslationHash = require("./scoped_translation_hash");
2222

2323
// remove path stuff we don't want in the scope
2424
var pathRegex = new RegExp(
25-
"^(" + HbsProcessor.prototype.directories.join("|") + ")(/plugins/[^/]+)?/"
25+
".*(" + HbsProcessor.prototype.directories.join("|") + ")(/plugins/[^/]+)?/"
2626
);
2727
ScopedHbsExtractor.prototype.normalizePath = function(path) {
2828
return path.replace(pathRegex, "").replace(/^([^\/]+\/)templates\//, '$1');

0 commit comments

Comments
 (0)