Comments (5)
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.
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.
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.
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.
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)
- Update typescript dependency requirement HOT 2
- Can not add multiline strings with JsExtractor HOT 1
- Allow #
- Allow #| comments HOT 1
- Add message does not allow null values HOT 1
- illegal operation on a directory HOT 3
- no strings found on keybase/client project HOT 1
- Add support for empty-attribute selectors HOT 1
- String templates are not parsed HOT 2
- Cannot extract context strings from identifiers HOT 1
- how can use for extract strings not translated into XREngine repo? HOT 10
- No extraction sometimes HOT 3
- Provide content options for HTML attribute extractor HOT 7
- Variable with type and without initializer causes error HOT 1
- gettext-extractor does not support private # HOT 1
- gettext-extractor fails when glob matches a directory HOT 2
- extracting comments not working in assignment HOT 3
- HtmlExctractors returns more characters than expected HOT 2
- Add async support
- Convert to ASM?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gettext-extractor.