PrecompilePlugin extends HandlebarsPlugin { private void i18nJs(final Handlebars handlebars, final List<CharSequence> extras, final URL[] classpath) { handlebars.registerHelper(I18nHelper.i18nJs.name(), new Helper<String>() { @Override public Object apply(final String context, final Options options) throws IOException { StringBuilder output = new StringBuilder(); output.append(" output.append(" output.append(registerHelper(I18nHelper.i18nJs.name(), "I18n.locale = arguments[0] || \"" + Locale.getDefault() + "\";\n" + "return '';", "arguments")); output.append(" output.append(registerHelper(I18nHelper.i18n.name(), "var key = arguments[0],\n" + " i18nOpts = {},\n" + " len = arguments.length - 1," + " options = arguments[len];\n" + "for(var i = 1; i < len; i++) {\n" + " i18nOpts['arg' + (i - 1)] = arguments[i];\n" + "}\n" + "i18nOpts.locale = options.hash.locale;\n" + "return I18n.t(key, i18nOpts);")); extras.add(output); return null; } @Override public String toString() { return I18nHelper.i18nJs.name() + "-maven-plugin"; } }); }  void setRuntime(final String runtime); void setMinimize(final boolean minimize); void setOutput(final String output); void setAmd(final boolean amd); void setPrefix(final String prefix); void setSuffix(final String suffix); void addTemplate(final String template); void setHandlebarsJsFile(final String handlebarsJsFile);  }
@Test public void i18nJs() throws Exception { PrecompilePlugin plugin = new PrecompilePlugin(); plugin.setPrefix("src/test/resources/i18nJs"); plugin.setSuffix(".html"); plugin.setOutput("target/helpers-i18njs.js"); plugin.setProject(newProject()); plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); plugin.execute(); assertEquals(FileUtils.fileRead("target/helpers-i18njs.js"), FileUtils.fileRead("src/test/resources/helpers-i18njs.expected").trim(), FileUtils.fileRead("target/helpers-i18njs.js").trim()); }