What are advantages of using babel-plugin-react-intl? - react-intl

I've been trying to learn and understand react-intl library and I encountered babel-plugin-react-intl library. There is a description in the library's page like that;
Extracts string messages for translation from modules that use React Intl.
I wonder that which string messages would be extracted?
Also, what are the benefits of extracted messages?

From: https://blog.johnphoto.se/2016/03/21/react-intl-v2/ (couldn't comment without more rep)
Once it is time to get all these messages translated, you only have to
do a webpack build with the babel-plugin react-intl plugin. This will
extract all the defined messages from the code base into JSON files.
These files are then sent to your translators and they translate all
of these messages and the translations is put into a flat JSON hash
and this is then loaded into your code and you have a i18n enabled
app. So enough with theory!

I am using babel-plugin-react-intl to automatically extract all the labels in my React application.
I'd point as main advantages the following two:
Using the plugin, all the labels from my application are automatically extracted to json files. Instead of having to manually update the json files that will be translated. This way, I don't need to worry about this file, as the plugin will push the labels to it.
If I accidentally create a duplicated ID for a label, the plugin tells me that by throwing an error on webpack.
Extra: I am not using, but, if you want to force developers to add a context description for each label, this plugin also has an option to force this behavior so that, if the developer forgets it, an error is thrown on webpack.

Related

How to use filepond with Django

As the title suggest.
I have searched Google and stackoverflow, so far I don't find any tutorial that doesn't involve (https://github.com/ImperialCollegeLondon/django-drf-filepond).
While this library seems maintain, at 68 stars, too much risk and I prefer to do without it.
What I tried
When you use filepond input tag with class file-uploader file-uploader-grid, in browser, it will compile and generate a div tag.
The issue is that the id in input will be generated under the div instead of input tag.
Without that id, when the form is submitted, self.request.FILES will be empty dictionary.
So I tried writing a JavaScript to add id to input tag, which don't work unfortunately.
Anyone successfully do it in Django without additional library? Thanks
The input generated is only there to catch files, the actual data is either stored in hidden input fields (if you use server property) or encoded in those fields (if you use file encode plugin).
You can set storeAsFile to true to have FilePond update the fileList property of a file field. But that doesn't work on older versions of iOS, see link in property description:
https://pqina.nl/filepond/docs/api/instance/properties/

How do I track down specifics for an opencart module that is rendering on my site but missing everything except the catalog template file?

I've inherited an opencart 1.5.5.1 site and am completely new to the cms. From what I've been able to gather, it was built by a competent developer but then went through a hack-it-up development team, and then on to me. So, I really don't know what all to expect from it.
I currently have a module that is rendering in the left sidebar and I don't know why it's rendering there. The only file I can find in the file stack related at all to this "module" is a single template file within the catalog directory structure called:
/catalog/view/theme/mytheme/template/module/affiliate_profile_select.tpl
All of the other installed modules on the site seem to have lots of other files associated with them, whose locations are verified by the research I've done on creating opencart modules: ie, module files in the following directories:
/catalog/controller/module/
/catalog/language/english/module/
/catalog/model/module/
/catalog/view/theme/mytheme/template/module/
/admin/controller/module/
/admin/language/english/module/
/admin/model/module/
/admin/view/template/module/
From what I've been able to find though, this single file (affiliate_profile_select.tpl) is the only file in the file stack that is associated with this module.
I can't find anything related to this module, and/or file, inside any of the vqmod php or xml files.
I can't find anything related to this module in the admin area. I've tried searching through all of the installed modules for other generic identifiers (the section view is rendering at the very top of the left-sidebar on most non-logged-in pages, so I'm looking for layout locations of "Left Sidebar" and positions less than 2), but haven't found anything.
And yet, the section is obviously rendering on the site, so it has to be there somewhere. In fact, it's rendering in two places. It's also in the top-content section of the mobile view of the home page.
Right now it's almost feeling like it was a module that had been written, installed, and configured, and then someone deleted all but one of the files associated with the module. Could a situation like that happen?
Is there any way to track this issue down by querying the database? Or would the template inclusion obviously be inside a file somewhere and I just need to find it? To complicate matters, the hosting company doesn't allow remote login with a console (from what I can tell). Otherwise I'd just have run a grep for the filename in case someone had just thrown an "include()" statement in somewhere. The only place I've checked for something like that so far was in the left-sidebar template file:
/catalog/view/theme/default/template/common/column_left.tpl
but it's just a simple for-loop that echoes out the module views.
Any help or direction on how I might be able to track this problem down would be of significant help.
In Opencart, .tpl (template) files are always called by controllers which as you probably guessed are in catalog/controller/. An if it's a module (showing in left sidebar position, it's probably going to be in catalog/controller/module/. First order of business would be to find the controller that's calling the template you referred to. I'd probably start by getting into a shell and doing something like this from the site's docroot:
grep -r affiliate_profile_select .
From there you should be able to find the associated module controller and any other logic involved. Sometimes people use vQmod to add something on to a pre-existing module so that can possibly explain the lack of other similarly named files.

Per-user color schemes with LESS/SCSS?

I've got a Django project spinning up where it would be great to have the UI in lots of color schemes based on the users' school colors. I have this fantasy of having a base variables.less file along with a bunch of other .less files that compile into style.css.
But once a user sets their school colors it generates a blue.variables.less file (if they've selected the blue preset) or school123.variables.less file (if they got all fancy and used the color picker to make their own color scheme) and then compiles everything to blue.style.css or school123.style.css and then that's the .css file we load when we serve the page.
I can imagine lots of ways for this to fall down. Like how do I reprocess all those files when I push an update to forms.less or layout.less.
Is there a better way to do this? I Googled my fingers raw but haven't found anyone attempting this madness.
There are quite a few ways to accomplish your goal of being able to have user specific color schemes, but they each have their advantages / disadvantages.
I'm assuming you are using some framework like Bootstrap with the files that you name.
Option 1: Inline CSS for color-specific styles (Preferred)
This is my preferred option due to performance and simplicity. You can store each of the customized colors for each user, or even creating a model so you can reuse colors that represent a specific school. It's stored in the database and can scale to an very large number of color schemes without generating a lot of very similar files.
Create a snippet in your template code that has any style that uses the color variable.
base.html
{% include "color-snippet.css" with main-color="{{ user's main color }}" alt-color="{{ user's alt color }}" %}
color-snippet.css (note this file will be in your templates directory as it's being handled by your template engine
<style>
.some-style {
color: {{ main-color }} !important;
}
</style>
So the big downside to this is you'll need to customize Bootstrap beyond the variables.less. You'll need to grep through the less files to find all the classes that would be generated, and copy the style to your snippet in css and not less. It'll take some investment up front and work when you want to upgrade to a newer Bootstrap, but it'll allow you to separate the color part of the styles to be derived dynamically at runtime.
I prefer this approach since you don't have to deal with compilation of less outside your collectstatic step.
Option 2: Client side compilation of LESS
You can have Django serve a file that is dynamically created and returns the variables you want. Then you can have less.js compile it on the client.
This would involve adding to your base template a url path that is handled by Django that isn't part of your static path (e.g. /style/variables), creating a handler in views and then returning text content that would be your less file variables.
Option 3: Server side compilation of LESS
I use Django Pipeline to do my server side compilation of less to css. It takes some setup to get working with your Django application. In development mode, Django Pipeline will compile on every request the associated less files into CSS files. In production mode, it'll point to the appropriate file path to the compiled file. It hooks into collectstatic so your less gets compiled when you collectstatic.
The biggest problem with this approach is that the mapping for your static files (what less + css files compile to css) is defined in your settings file. This requires a server restart when you update this. You could base your own server side less compilation off how Django Pipeline works but have logic for the mapping instead of defining it in something that requires a server restart.
It's a lot of work and the less compilation of Bootstrap is non-trivial to have to do on every request.
If you created your own mapping that doesn't require you to restart your Django server process, you could always just run collectstatic to create the new css files. This would avoid compilation at every request.
While this last approach is closest to what you mentioned, it seems a lot more work and error prone than just separating the color-specific styles and using django templating to customize it.
The last approach as well works well if your number of schemes is rather low since you can just create all the mappings ahead of time and not let people generate their own at runtime. They can suggest them and you can just update them at some regular cadence.

Angular's template with external js libraries

I have made element directive, which works with template through templateUrl parameter. This template contains fileupload input, which needs about 8 external js libraries (jquery fileupload plugin). If I have links to these js libraries in template (using standard script element), than everything works fine, but there is an error in browser console on loading:
Error: $digest already in progress
If I put the links to js libraries directly to the page, where I have my directive, there is no error, but it is not good way for reusability.
Are you trying to trigger a $digest manually?
If this is the case, I strongly recommends you to change the approach, as you should let the Angular decides the best time for a $digest. If it's not possible to change, then you should be sure you're not calling a $digest()/$apply() inside an $digest cycle. One of the ways to do so is ensuring !scope.$$phase.

Translate xml content using web service API from Ektron CMS400.Net

First of all: I'm on Ektron CMS v8.1
I'm having a problem with dynamicly adding translated content to the cms via the Webservice API. I can perfectly add xml content by using the following object and method:
ContentSoapClient csc = new ContentSoapClient("ContentSoap");
csc.AddContent3(...);
I specify a language and the xml content gets inserted. But now I want to add a translated version of the xml to the cms. So I want it to have the same contentId!
Anyone has an idea on this? The only method in the csc object that recieves a contentId is 'csc.AddContent2(..)' But that doesn't import anything and just gives me an error saying my xml is incorrect. While my xml is correct..I checked it!
Thanks!
Found the answer..
Ektron apparantly uses alot of asmx files and I only checked the "/workarea/webservices/WebServiceAPI/Content/Content.asmx" webservice. I found the method 'AddTranslatedXMLContent()' I need in the "/Workarea/webservices/ContentWS.asmx" webservice.
I wish they just cleaned up their API... Would save us a lot of trouble.
Firstly, I haven't used the ContentSoapClient class and can't find any documentation on it.
Ektron often takes a language id when you create the API object. See if the ContentSoapClient contructor can take a Language Id.