Skip to content

Instantly share code, notes, and snippets.

@dannycoates
Created April 6, 2018 20:31
Show Gist options
  • Save dannycoates/31e5edf1db6328bb475894459fa48203 to your computer and use it in GitHub Desktop.
Save dannycoates/31e5edf1db6328bb475894459fa48203 to your computer and use it in GitHub Desktop.
diff --git a/frontend/src/app/containers/App/index.js b/frontend/src/app/containers/App/index.js
index 5d34ca2d..b2b3197a 100644
--- a/frontend/src/app/containers/App/index.js
+++ b/frontend/src/app/containers/App/index.js
@@ -1,7 +1,7 @@
/* global ga */
import { MessageContext } from "fluent/compat";
import { negotiateLanguages } from "fluent-langneg/compat";
-import { LocalizationProvider } from "fluent-react/compat";
+import { LocalizationProvider, isReactLocalization } from "fluent-react/compat";
import React, { Component } from "react";
import { connect } from "react-redux";
@@ -45,6 +45,11 @@ export function shouldShowUpgradeWarning(hasAddon, hasAddonManager, thisIsFirefo
return true;
}
+let xxx = false;
+function logL10n(id) {
+ if (xxx) { console.error(`missing l10n for ${id}`); }
+}
+
class App extends Component {
constructor(props) {
@@ -145,6 +150,7 @@ class App extends Component {
);
Promise.all(promises).then(() => {
+ xxx = true;
this.props.setLocalizations(langs);
const staticNode = document.getElementById("static-root");
if (staticNode) {
@@ -177,12 +183,30 @@ class App extends Component {
}
}
}
+ const Logger = ({children}, context) => {
+ if (!context.l10n._getMessageContext) {
+ context.l10n._getMessageContext = context.l10n.getMessageContext
+ context.l10n.getMessageContext = (function (id) {
+ const ctx = this._getMessageContext(id)
+ if (!ctx) {
+ logL10n(id);
+ }
+ return ctx;
+ }).bind(context.l10n)
+ }
+ return children
+ }
+ Logger.contextTypes = {
+ l10n: isReactLocalization
+ }
return <LocalizationProvider messages={ generateMessages(
this.props.negotiatedLanguages,
this.props.localizations
) }>
- { React.cloneElement(this.props.children, this.props) }
+ <Logger>
+ { React.cloneElement(this.props.children, this.props) }
+ </Logger>
</LocalizationProvider>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment