It would be great if I could define my namespaces with patterns like the following:
{
"*/new": ["forms"],
"*/[id]/edit": ["forms"]
}
I thought about this 馃檪Ok, let's do it!
@aralroca when you see my config you will know why :D
@BjoernRave what do you think if instead of glob patterns, we will support regExp when it exist the prefix rgx:?
Ex:
{
'rgx:^.*/test/.*/example$': ['namespace'] // /this/test/is/an/example -> true
}
In this case, we can provide more flexibility without bringing extra code. The problem of Glob is that we need to do all the conversions or use an external library. In static websites is not a problem because this code is only for the CLI, but in the case of appWithI18n is going to increase the size of that package.
@aralroca not sure. I myself am not super fluent with regexes, same for many people I think.
Glob patterns seem to be like a standard for this kind of configuration.
I like the idea of regex support, since its native in javascript it would keep the library tiny
Ok @BjoernRave @Hanzo93 . Let's do a list of pros and cons:
| Pros/Cons | Globbing | Regex |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
| Versatility | 馃憥Good enough, but regex is much richer. | 馃憤 You can do far more complicated things with regular expressions. |
| Lib size | 馃憥Requires to implement a glob to regex conversor or to import an external lib... So is adding extra kb to the bundle size. | 馃憤Is native in JavaScript, so is possible to implement without writing so much code. |
| Maintenance | 馃憥 We will need to maintain that extra code of Glob to Regex conversor. | 馃憤TC39 is mantaining the RegExp for us. |
| Easy to use | 馃憤Easy to learn and remember, is very simple. | 馃憥Hard to learn and sometimes can be frustrating. |
| Performance | 馃憥 Similar performance than regex but with an additional step to convert Glob to Regex. | 馃憤Very similar to glob, but without the additional step. |
Do you want to add any points to the list?
I researched and there are a lot of libraries, like webpack, jest, babel that are using regex in their configurations.
@aralroca thanks for that comparison. I guess looking at it, Regexes make more sense. It's fine by me if you guys prefer it. Will be a way to improve my Regex game :D
@BjoernRave can you confirm that with the new 0.9.0 release is working well in your project?
Your example:
{
"*/new": ["forms"],
"*/[id]/edit": ["forms"]
}
Should be:
{
"rgx:/new$": ["forms"],
"rgx:/\\[id\\]/edit$": ["forms"]
}
or with both rules:
{
"rgx:(/new|/\\[id\\]/edit)$": ["forms"],
}
@aralroca when I install latest I only get 0.8.0
@BjoernRave you are right, I forgot to publish to npm, now is ready https://www.npmjs.com/package/next-translate?activeTab=versions
@aralroca can confirm, that it works, good job :)
Most helpful comment
I like the idea of regex support, since its native in javascript it would keep the library tiny