Skip to content

Commit

Permalink
Move expFormat helper to global context
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed Oct 17, 2024
1 parent 654700a commit b46c686
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/templates/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import pt_br from "../i18n/pt-br.yaml";
import pt from "../i18n/pt.yaml";
import { TranslationNotFoundError } from "./errors";

// TODO: Can this be in the global context.
Handlebars.registerHelper("exp-format", (context) => expFormat(context));

/**
* Pulled from EFP. Function to convert researcher's text to HTML.
*
Expand Down Expand Up @@ -83,6 +86,7 @@ export const getTranslation = (lcl: Intl.Locale) => {
*/
const initI18next = (trial: TrialType<PluginInfo>) => {
const debug = process.env.DEBUG === "true";
// TODO: Catch Locale error when bad locale
const lcl = new Intl.Locale(trial.locale);
const translation = getTranslation(lcl);

Expand All @@ -105,15 +109,14 @@ const initHandlebars = () => {
Handlebars.registerHelper("t", (context, { hash }) =>
i18next.t(context, hash),
);
Handlebars.registerHelper("exp-format", (context) => expFormat(context));
};

/**
* Initialize both i18next and Handlebars.
*
* @param trial - Yup
*/
export const initI18nAndTemplates = (trial: TrialType<PluginInfo>) => {
export const initI18nAndHelpers = (trial: TrialType<PluginInfo>) => {
initI18next(trial);
initHandlebars();
};

0 comments on commit b46c686

Please sign in to comment.