Git Product home page Git Product logo

Comments (11)

Hanzo93 avatar Hanzo93 commented on May 13, 2024 3

I like the idea of regex support, since its native in javascript it would keep the library tiny

from next-translate.

aralroca avatar aralroca commented on May 13, 2024 1

I thought about this ๐Ÿ™‚Ok, let's do it!

from next-translate.

BjoernRave avatar BjoernRave commented on May 13, 2024 1

@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.

from next-translate.

aralroca avatar aralroca commented on May 13, 2024 1

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.

from next-translate.

BjoernRave avatar BjoernRave commented on May 13, 2024 1

@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

from next-translate.

BjoernRave avatar BjoernRave commented on May 13, 2024 1

@aralroca can confirm, that it works, good job :)

from next-translate.

BjoernRave avatar BjoernRave commented on May 13, 2024

@aralroca when you see my config you will know why :D

from next-translate.

aralroca avatar aralroca commented on May 13, 2024

@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.

from next-translate.

aralroca avatar aralroca commented on May 13, 2024

@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"],
}

from next-translate.

BjoernRave avatar BjoernRave commented on May 13, 2024

@aralroca when I install latest I only get 0.8.0

from next-translate.

aralroca avatar aralroca commented on May 13, 2024

@BjoernRave you are right, I forgot to publish to npm, now is ready https://www.npmjs.com/package/next-translate?activeTab=versions

from next-translate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.