Code Monkey home page Code Monkey logo

Comments (5)

lukasgeiter avatar lukasgeiter commented on September 3, 2024

I actually implemented it this way on purpose. This way a conflict with the preserveIndentation option is avoided. Let's look at an example:

<p>
    Lorem ipsum
    dolor sit amet
</p>

The raw content of the element is:

\n    Lorem ipsum\n    dolor sit amet\n

With trimWhiteSpace = true and preserveIndentation = false (the default) we will get:

Lorem ipsum\ndolor sit amet

With trimWhiteSpace = true and preserveIndentation = true we get:

    Lorem ipsum\n    dolor sit amet

Now I agree that the documentation doesn't fully describe how the option works.

I would appreciate if you could share your use case with me so I can determine whether it makes sense to release a new version or if it is enough to update the documentation. Thanks!

from gettext-extractor.

markatrosie avatar markatrosie commented on September 3, 2024

I see what you mean. I think it would be nice if it used the current regex or the one I'm recommending above contextually based on whether trimWhiteSpace && preserveIndentation or trimWhiteSpace && !preserveIndentation, but doing that would probably cause a lot of headaches in the current userbase.

Maybe instead just a documentation update to clarify how trimWhitespace behaves?

As for my use case -- I was just trying to generate "clean" message IDs. Once I discovered this quirk, I was able to work around it. The challenge is that I'm consuming my language files inside a web browser and I need my JS to extract message IDs from markup the same way gettext-extractor does so they line up. I was trying to replicate trimWhiteSpace = true in the browser by using theMarkup.trim() and running into issues when the markup started with a tab. Once I encountered this problem, it was simple enough for me to switch to trimWhiteSpace = false and preserveIndentation = true and let both the browser and gettext-extractor use the raw, untouched content.

from gettext-extractor.

lukasgeiter avatar lukasgeiter commented on September 3, 2024

Thanks for your answer. If your goal is to generate "clean" message IDs why not just use the same regex for removing indentation during runtime?

I'm still contemplating what to do here and having message ids like this doesn't seem very desirable to me:

Lorem ipsum
    dolor sit
    amet

from gettext-extractor.

markatrosie avatar markatrosie commented on September 3, 2024

Because I expected trimWhiteSpace to behave the same as String.prototype.trim. Once I dug into the code and realized it didn't, I felt it was better to just leave things untouched on both sides. Copying the regex out of gettext-extractor would have worked for me, too.

from gettext-extractor.

lukasgeiter avatar lukasgeiter commented on September 3, 2024

Sorry for my late response. I've now added a comment to the documentation that hopefully makes it clear enough that, in combination with preserveIndentation, it doesn't exactly behave like .trim().

from gettext-extractor.

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.