DISCLAIMER: Please, do not start "singlequotes masterrace", "tabs are over spaces"-related shitstorms. Thanks :)
I wonder how to make this possible:
Project is using 4 spaces and doublequotes
I am using 2 spaces and singlequotes
Import project
Every opened file translate to 2 spaces and singlequotes
Save project as 4-spaces and doublequotes based
Commit it as 4-spaces and doublequotes files
I am web developer, JS ES6 (without flow), JSX (react), mainly using VS code.
This is not essental I 'can' stick to the project rules. But this will save me much time.
Thanks for advices!
You could do this with Git smudge/clean filters. A pre-requisite is that you have a tool that does the conversion of 4 spaces and double quotes to 2 spaces and single quotes and vice versa. Assuming you have these two, let's call them 4to2converter and 2to4converter, do the following:
Edit (or create) your .gitattributes file by adding a line like this:
*.js filter=convert
This tells git that it should apply convert filter on all .js files. You can include other file types as well.
Then define what the convert filter does by adjusting git config:
$ git config filter.convert.smudge 2to4converter
$ git config filter.convert.clean 4to2converter
What happens now is that every time you commit .js files, the file is first ran through 2to4converter, and every time you do a checkout, it is first ran through 4to2converter.
Finally, ensure first that you don't have any uncommitted work, and run:
$ git checkout HEAD -- **
This forces a checkout on all files, applying your newly defined filter.
Related
I'm trying to use the "node-tesseract-ocr" module with electron to perform some basic image-to-text translations, but I'm having issues that I cannot seem to figure out, for the life of me. I'm using the exact same code as provided in the example (seen here: https://www.npmjs.com/package/node-tesseract-ocr), except I've changed the "lang" parameter for the configuration to the name of my custom .traineddata file. I've installed Tesseract manually alongside this, and have set the PATH variables for Tesseract ("C:\Program Files\Tesseract-OCR" and "C:\Program Files\Tesseract-OCR\tessdata"), and have placed the .traineddata file inside of the \tessdata folder.
Here's the error:
Command failed: tesseract "./screen.png" stdout -l mc --oem 1 --psm 3
Error opening data file C:\Program Files\Tesseract-OCR/tessdata/mc.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'mc'
Tesseract couldn't load any languages!
Could not initialize tesseract.
I have no idea why the slashes swap midway through the path to the .traineddata file; I'm assuming this is the issue, but I have no idea how to fix this, as it seems to be an issue with Tesseract itself.
Did I install an incorrect version or something? (I installed Tesseract using "tesseract-ocr-w64-setup-v5.2.0.20220712.exe" from "https://digi.bib.uni-mannheim.de/tesseract/", as suggested by "https://medium.com/quantrium-tech/installing-and-using-tesseract-4-on-windows-10-4f7930313f82").
Everything works perfectly fine when using "eng" as the language, except the characters are not always read properly (since I'm attempting to read characters from a game, rather than handwriting/a standard English font, which is why I need the custom .traineddata file to work).
Any help is appreciated.
I used the installation from https://github.com/UB-Mannheim/tesseract/wiki and it seems to work now. Not sure why the other installation was bugged, but oh well.
I like the automated organize feature in VSCode, but having it doing it on every save has given me some trouble.
...
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
...
Is it possible to set up some git hooks that organize the imports (either via vscode or some other script/lib) when I stage them?
Issues
If I hit save too early (do it to kick off prettier all the time) before I have used the imported methods - then it removes it and I have to write the import again.
If I break the code (.jsx) and something appears to not be used and I hit save (to trigger prettier), then it removes the imports. I then have to import them again.
There is some form of hook that can be applied when running git add : filters defined in gitconfig and .gitattributes.
See this section of git book for detailed explanations.
Here are the sketches from the documentation (it illustrates how you can configure a filter to run on *.txt files) :
when running git add :
when running git checkout :
You can define in your gitconfig a filter, which consists of two commands to "clean" and "smudge" :
$ git config --global filter.jsximports.clean fiximports
$ git config --global filter.jsximports.smudge cat
and edit the .gitattributes file to apply this filter on jsx files
*.jsx filter=jsximports
The script to apply may be tslint --fix, with the ordered-imports rule.
Actually : tslint's rule seem to have its own implementation, but it does something similar (see https://github.com/palantir/tslint/pull/4064)
In this answer : https://stackoverflow.com/a/57458656/86072
user thorn points to this npm package :
https://www.npmjs.com/package/organize-imports-cli
which calls organizeImports from cli
I have been reading about this for days, and nothing seems to be working. I have seen a lot of documentation of this issue, but none of the work arounds are working for me.
I have :
Rails 5.0.1
* sprockets (3.7.1)
* sprockets-rails (3.2.0)
* i18n (0.7.0)
* i18n-js (3.0.0.rc15)
config/i18n-js.yml
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
config/application.rb
config.middleware.use I18n::JS::Middleware
When I add new translations to the corresponding yml file, the i18n/translations.js does not update to include the new .yml translations.
For example, in en.yml:
en:
form_error:
tos_check: "You must agree to Lexody's Terms of Use to continue."
choose_city: "Please select a city from the menu."
cancel_reason: "Please provide a reason for cancelling."
$('.prompt').html('<p style="color:#e57373">' + I18n.t('form_error.cancel_reason') +'</p>');
returns: [missing "en.form_error.cancel_reason" translation]
I have tried:
Deleting translations.js and run rake i18n:js:export
rake tmp:cache:clear
rake assets:precompile
Does anyone have another solution I can try? Thanks!!
Update
After looking at the additional configuration files, this config/i18n-js.yml seems suspect:
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
According to the export configuration docs, the only key refers to the translation keys to be exported, not the filenames. So '*.js*' will match nothing, causing no translations to be exported.
Change this file to read:
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*'
(Original answer below)
Working example
Here's a minimal, working example that produces expected behavior with the i18n-js gem:
#!/bin/bash
rails _5.0.1_ new .
echo "gem 'i18n-js', '3.0.0.rc15'" >> Gemfile
echo " NEW_KEY: NEW_VALUE" >> config/locales/en.yml
bundle install
bundle exec rake i18n:js:export
grep -o '"NEW_KEY"' public/javascripts/translations.js
For me, running the above script outputs "NEW_KEY" on the last line, as expected (demonstrating that NEW_KEY is correctly added to public/javascripts/translations.js after running i18n:js:export in a fresh Rails installation), which means something else is going on in your local project.
Further investigation
In order to know what else exactly is going on, you'll have to further investigate exactly what configuration you've changed locally when compared to a fresh Rails installation.
(Note that the easiest way to do this is to provide a Minimal, Complete and Verifiable example, such as a link to a GitHub repo that produces your issue exactly.)
you say "the i18n/translations.js does not update to include the new .yml translations.", but the default path that gets updated is public/javascripts/translations.js. If you're using a non-standard path for your translations.js file, do you have additional configuration for this in config/i18n-js.yml? (If so, please share the entire contents of this file).
Have you confirmed that the new translation doesn't show up in translations.js at all (e.g., using a grep command like the one above)? Or is it possible that the issue is related to the asset pipeline configuration instead?
Not sure if you mean dev or prod env. I had a similar problem in my dev env and I solved it by adding config.middleware.use(I18n::JS::Middleware) to config/application.rb. You can check it here. Hope it helps.
In the .yml file, check for a colon after the language code.
Your example reads:
en
form_error:
cancel_reason: "Please provide a reason for cancelling."
Try:
en:
form_error:
cancel_reason: "Please provide a reason for cancelling."
I haven't tried exercising an example with this. However, the .yml files in the projects I have copies of all have colon after the language name. And it's just the sort of infuriating typo that might be invisible to someone close to it. Grr!
It seems that you have the English translation but is trying to access french locale instead.
I am using RequireJS optimizer in a gulp recipe to compile and concatenate my Modules but redundant 3rd party library files like bower.json and *.nuspec files are being copied to my output directory.
I have successfully managed to exclude full directories using fileExclusionRegExp in the requirejs.optimize options object with the following expression:
/^\.|^styles$|^templates$|^tests$|^webdriver$/
However, I cannot figure out how to exclude everything but .js file extensions. I could use the following:
/^\.|.json$|.nuspec$|^styles$|^templates$|^tests$|^webdriver$/
to exclude specific extensions but if a new type were to appear later, I would have to notice and then change the regex. Also, the regex would probably become unruly and hard to maintain with time. I have tried to use the following expressions:
/^\.|!js$|^styles$|^templates$|^tests$|^webdriver$/
/^\.|!.js$|^styles$|^templates$|^tests$|^webdriver$/
/^\.|^.js$|^styles$|^templates$|^tests$|^webdriver$/
/^\.|[^.js$]|^styles$|^templates$|^tests$|^webdriver$/
/^\.|[^.js]$|^styles$|^templates$|^tests$|^webdriver$/
The results ranged from doing nothing (the first 3, to breaking the build, last 2) any help anyone could provide would be appreciated.
Thanks
Try this regex:
^\.|\.(json|nuspec)$|^(styles|templates|tests|webdriver)$
I want to use the google closure compiler on the javascript source we're using.
In development mode we tend to break functionality to lots of files but for production would like to have them combined into modules.
When calling the compiler I can give it a list of files to include for compilation, but the output of that shows that the compiler did not save the order of the files list.
I searched about it and found that I can use goog.provide/good.require in order to control the dependencies between the different js files.
The problem with that is that it adds code to my js which I just don't need or want, for example:
goog.provide("mainFile")
will add this:
var mainFile = {};
to the compiled js file, something that I don't want.
We're not using the google closure library at all, all I want to use is the compiler.
Is there a way to tell the compiler the order of the files without including more "closure library" functionality which I have no need for?
I can of course create a tool of my own which will first take all the files, combine them into one which will then be the input of the compiler, but I would prefer to void that if it can be done by the compiler itself.
Edit
The goal is to be able to produce modules like the answer in this thread: Using the --module option in Closure Compiler to create multiple output files
And so I want to add to that the ability to control which files go into which module while also having control on their order.
For now I don't use wildcards, but I plan to do so in the future (if it's possible).
simply "cat file1.js file2.js > combined.js && compile..." is fine, but in our case it's a bit more complicated and we'll have to write a program/script that does that based on some logic.
If we can somehow tell the compiler the order of the files in advanced it might just save the time of implementing such a program.
Thanks.
Closure-compiler's ability to create multiple output files provides a powerful tool to separate input files into distinct output chunks. It is designed such that different chunks can be loaded at differing times depending on the features required. There are multiple compiler flags pertaining to chunks.
Each use of the --chunk flag describes an output file and it's dependencies. Each chunk flag follows the following syntax:
--js inputfile.js
--chunk name:num_files:dependency
The resulting output file will be name.js and includes the files specified by the preceding --js flag(s).
The dependency option is what you will be most interested in. It specifies what the parent chunk is. The chunk options must describe a valid dependency tree (you must have a base chunk).
Here's an example:
--js commonfunctions.js
--chunk common:1
--js page1functions.js
--js page1events.js
--chunk page1:2:common
--js page2function.js
--chunk page2:1:common
--js page1addons.js
--chunk page1addons:1:page1
In this case, you are telling the compiler that the page1 and page2 chunks depend on the common chunk and that the page1addons chunk depends on the page1 chunk.
Keep in mind that the compiler can and does move code from one chunk into other chunk output files if it determines that it is only used by that chunk.
None of this requires closure-library or the use of goog.require/provide calls nor does it add any code to your output. If you want the compiler to determine dependencies automatically or to be able to manage those dependencies for you, you'll need to use a module format such as CommonJS, ES2015 modules or goog.require/provide/module calls.
Update Note: Prior to the 20180610 version, the chunk flags were named module. They were renamed to reduce confusion with proper JS modules. The answer has been updated to reflect the new names.
Update Note 2: There is now a utility to automatically calculate and generate these flags for you: https://github.com/ChadKillingsworth/closure-calculate-chunks
You can also set the output path, for example with:
--module_output_path_prefix ./public/js/
See also:
Using the --module option in Closure Compiler to create multiple output files