Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request getPathWithoutLocale #30

Open
3 tasks done
reslear opened this issue Oct 18, 2023 · 3 comments
Open
3 tasks done

feature request getPathWithoutLocale #30

reslear opened this issue Oct 18, 2023 · 3 comments
Labels
feature Includes new features status: proposal Request for comments

Comments

@reslear
Copy link

reslear commented Oct 18, 2023

Clear and concise description of the problem

need write regexp
like this \/\S{0,2}\/?landings\/?(.+)? - is simple en/fr (but is en_US?)

http://localhost:3010/davos
http://localhost:3010/landings/davos
http://localhost:3010/landings
http://localhost:3010/landings/
http://localhost:3010/fr/landings/davos
http://localhost:3010/fr/landings
http://localhost:3010/fr/landings/

Suggested solution

it would be convenient to parse h3 routers on the server for example function: getPathWithoutLocale

http://localhost:3010/fr/landings -> /landings
http://localhost:3010/en_US/landings -> /landings

Alternative

No response

Additional context

No response

Validations

@reslear reslear added the feature Includes new features label Oct 18, 2023
@kazupon
Copy link
Member

kazupon commented Oct 19, 2023

Thank you for your feedback!

This library is provided as utils specialized for i18n
What you are proposing is an API to get the non-locale part of the path.
That does not fit the policy of this library, but I would like to know more about why you want that API or not.

@kazupon
Copy link
Member

kazupon commented Oct 19, 2023

BTW, getLocalePath has options, which has parser option.
https://github.com/intlify/utils/blob/main/src/h3.ts#L237

@kazupon kazupon added the status: proposal Request for comments label Oct 19, 2023
@reslear
Copy link
Author

reslear commented Oct 19, 2023

need for example on route middleware and parse url, where language doesn't matter, but the correct path is important:

export default defineNuxtRouteMiddleware((to, from) => {
  
  // before
  if (/\/\S{0,2}\/?landings\/?(.+)?/.test(to.path)) {}
  
  // or using getLocalePath
  if(getPathLocale(to.path).baseName.replace(loc, '').startsWith('/landing/')) {}
  
  // after - more safe and easy 
  if(getPathWithoutLocale(to.path).startsWith('/landing/')) {}
  
  // or maybe naming simple - getPath / getBasePath / getRawPath / parsePath ? 
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Includes new features status: proposal Request for comments
Projects
None yet
Development

No branches or pull requests

2 participants