Skip to content

Conversation

@NekoOs
Copy link

@NekoOs NekoOs commented Apr 21, 2024

Overview

This pull request updates the regex used in the obtainLangs function of multilang.js to better handle a variety of filename conventions. The update is critical for projects that include files with complex names or paths.

Changes

  • The regex pattern has been changed from /([a-z]{2}):([^.]+\.(md|html))/g to /([a-z]{2}):(.+?\.(md|html))/g.
  • This enhancement allows the function to support filenames that contain spaces, multiple periods, and different directory paths.

Rationale

The previous regex failed to parse filenames with periods that were not at the position of the file extension (e.g., example.test.md) and did not support filenames with spaces or paths (e.g., ../my docs/example.md). These limitations hindered the usability of the multilang library in environments where file naming conventions vary and include more complex structures.

Benefits

  • Increased flexibility in file naming conventions supported by the multilang tool.
  • Improved reliability and robustness of language detection and file handling.

This update is crucial for users who manage documentation in multiple languages across various directories and naming conventions, ensuring broader usability and fewer errors in file processing.

Updated the regular expression in the `obtainLangs` function within `multilang.js` to better handle filenames with spaces, periods, and paths. The previous regex pattern `/([a-z]{2}):([^.]+\.(md|html))/g` was limited in that it did not support filenames containing periods outside of the extension or spaces. The new pattern `/([a-z]{2}):(.+?\.(md|html))/g` allows for filenames with multiple periods and spaces, accommodating more complex file naming conventions and paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant