I18nModuleBuilder extends JavaScriptModuleBuilder { @Override public boolean handles(String mid, IResource resource) { Matcher m = re.matcher(mid); return super.handles(mid, resource) && m.matches() && m.group(5).length() == 0; }  @Override ModuleBuild build(String mid, IResource resource,
			HttpServletRequest request, List<ICacheKeyGenerator> keyGens); @Override String layerBeginEndNotifier(EventType type, HttpServletRequest request, List<IModule> modules, Set<String> dependentFeatures); @Override List<ICacheKeyGenerator> getCacheKeyGenerators(IAggregator aggregator); @Override boolean handles(String mid, IResource resource); static String OPTION_DISABLE_LOCALE_EXPANSION; }
@Test public void testLocaleMatching() throws Exception { String s; requestAttributes.put(IHttpTransport.EXPORTMODULENAMES_REQATTRNAME, Boolean.TRUE); builder = new I18nModuleBuilder(); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"en-us-var"})); ModuleBuild build = buildIt(); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{en-us-var")); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(1, build.getExtraModules().size()); Assert.assertEquals("nls/en-us-var/strings", build.getExtraModules().get(0)); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"en-ca-var"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{en-ca}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(1, build.getExtraModules().size()); Assert.assertEquals("nls/en-ca/strings", build.getExtraModules().get(0)); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"es-ca-var"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{es}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(1, build.getExtraModules().size()); Assert.assertEquals("nls/es/strings", build.getExtraModules().get(0)); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"ex-ca-var"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(0, build.getExtraModules().size()); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"en-ca"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{en-ca}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(1, build.getExtraModules().size()); Assert.assertEquals("nls/en-ca/strings", build.getExtraModules().get(0)); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"en-cx"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{en}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(1, build.getExtraModules().size()); Assert.assertEquals("nls/en/strings", build.getExtraModules().get(0)); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"en"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{en}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(1, build.getExtraModules().size()); Assert.assertEquals("nls/en/strings", build.getExtraModules().get(0)); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"ex"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(0, build.getExtraModules().size()); requestAttributes.put( IHttpTransport.REQUESTEDLOCALES_REQATTRNAME, Arrays.asList(new String[]{"es", "en-us", "en-ca-var", "foo"})); s = KeyGenUtil.generateKey(mockRequest, keyGens); System.out.println(s); Assert.assertTrue(s.contains("i18n{es,en-us,en-ca}")); build = buildIt(); Assert.assertEquals(expectedOutput, build.getBuildOutput()); Assert.assertEquals(3, build.getExtraModules().size()); Set<String> mids = new HashSet<String>(); for (String mid : build.getExtraModules()) { mids.add(mid); } Assert.assertEquals( new HashSet<String>(Arrays.asList(new String[]{"nls/es/strings", "nls/en-us/strings", "nls/en-ca/strings"})), mids); Assert.assertFalse(builder.handles("nls/en/strings", new FileResource(new File(en, "strings.js").toURI()))); }