Dreamweaver Dreamweaver - 5 months ago 53
AngularJS Question

Is it possible to add suffix as regex in $translateProvider.useStaticFilesLoader in agularJs Translation?

In angularJs translation config can we have $translateProvider.useStaticFilesLoader suffix property as an regex.

Lets say below is a sample config :

$translateProvider.useSanitizeValueStrategy('sanitize');
$translateProvider.useStaticFilesLoader({
files: [{
prefix: 'i18n/local-',
suffix: '.json'
}]
});
$translateProvider
.preferredLanguage("en");


Instead suffix to be '.json', is it possible to make it as

$translateProvider.useSanitizeValueStrategy('sanitize');
$translateProvider.useStaticFilesLoader({
files: [{
prefix: 'i18n/local-',
suffix: '-[0-9a-f]{8,10}-?.json'
}]
});
$translateProvider
.preferredLanguage("en");


Thanks.

Answer

No it's not and it is easy to understand why, $translate need to be able to build the exact url of your file. So if you start with :

  prefix: 'i18n/local-',
  suffix: '.json'

The url for en will be il8n/local-en.json.

If you use a regex as a suffix, how can he build the full URL of the file ? It just can't.

EDIT :

The OP goal was to trick the cache : here is the solution given :

prefix: 'i18n/local-', suffix: '.json?random='+generateRandomString()