Localization Angular 9 Medium size application - javascript

We have developed an application in Angular 9 (Only English words), Now we need to support Spanish language as well. all labels and headings are defined in HTML pages.
is there any way Can I convert all pages to Spanish with out creating / reading constant files (entering all headings and labels in constant .ts or JSON file)
I see ngx-translate but I see it's using constant files and reading it. (https://stackblitz.com/github/ngx-translate/example?file=src%2Fapp%2Fapp.module.ts)
If I need to follow the same, I need to create each page (Our application has 100 pages approx) data in JSON and read from it.
Please suggest if there is any easy solution to convert or suggest best way to implement it.
Thank you in advance.

the best way would still be creating a json file for each language and read from it. it helps you extends more language, for example some day you need french, japness, hindy, chinese...
by the way ngx-translate seems outdated, there is also transloco, which works great

Related

Export html tables to Excel using (or not) javascript

I made an statistics application which only permits actually to display various informations, using angular. Now i want to improve it.
On a page i have 3 big html tables containing the statistics and i'd like to let the users download them to use them on excel.
I've seen many ways to do it only in javascript but it's a bit too basic and for example, we can ony create one sheet by excel file. I used for a previous project a php Class to create my excel files which was really better.
Can you advise me about a way to create a more complex excel file, on my angular application, by calling maybe an external script or something?
Thank you very much
There are a plenty of solutions for your problem. All depends of your application, backend capabilities, frameworks used and so on...
A solution could be to create a webservice that uses the Apache POI apis.

AngularJS parsed JSON data vs plain pre filled HTML text

I was developing a simple site with multilingual function. My stack was AngularJS + JSON, basically a JSON file with different context in different languages.
Then I started to think if it is indeed a better solution in terms of performance to parse simple text from JSON and substitute text content variable values on the fly versus just creating a simple .html page for one language and another .html page for another language with text inside the html pre filled and then just using angular to change those pages by using route.
I would gladly hear out any thoughts about which method to use, or maybe you have a suggestion for a totally different approach in order to optimise the loading and rendering time of a page.
Thanks in advance for your time!
It is always better to use JSON files for the same. You can use i18n library for the multilingual purpose. With this you will be having multiple JSON's for each language and a single .html file. i18n will handle the language switching, there is no need to create route for each language. If you need to accommodate more languages in future, that can be achieved easily. Please refer the below link for more details.
https://angular-translate.github.io/

How to create and download a file in PDF and docx format which is to be created from the data in table in AngularJS?

I'm a newbie to AngularJS and using AngularJS for my web app.
On one page of my web app, I'm fetching data from database and displaying in a table. The data is in JSON format. And, since it contains multiple entries of the same type, it's an array.
I want to provide a Download button to the user and a radio button with the options of .pdf and .docx.
The User will select one of the file formats and click on Download button in order to download the data displayed in table into the selected file format on his/her local machine.
How to achieve it? Can someone please guide me in this regard?
Since the code to fetch and display data in table is too big that's why I haven't given any code snippet here.
If you want I can provide you the same.
If you can explain with some completely working examples for both file formats(.docx and .pdf) in AngularJS it would be really really great to me and other buddies.
Thanks.
There are some few good resources. I use https://mozilla.github.io/pdf.js/ for PDF and https://github.com/evidenceprime/html-docx-js for docx though it needs some manipulations.
Try these that I could find. This is not supposed to be a list of options but each of them have different functionalities. But it surely does not make sense making your own port for these.
PDF
http://pdfkit.org/ for extended PDF formatting
https://github.com/tuckerjt07/pdfmake allows for PDF formatting
https://github.com/Prashanth-Nelli/jsPdfTablePlugin Straight forward simple usage
http://github.com/MrRio/jsPDF frequently used
DOCx
http://github.com/MrRio/DOCX.js
https://github.com/evidenceprime/html-docx-js
Angular UI-Grid has implemented PDF/CSV Export from grid.
Please refer UI-Grid Export Data
They are using Pdfmake to generate PDF of exported data.
just google for a javascript library that enable you to easily convert your json data to PDF, something like http://github.com/MrRio/jsPDF – Naigel Mar 29 at 9:52
the same person also created this http://github.com/MrRio/DOCX.js – jcubic Mar 29 at 9:54
I'd agree, there's nothing gained from building it yourself unless it's a specialised system, but yours sounds like a very standard way of doing things so it would be far better to use a pre-made system and not waste the time that could be spent better developing the bespoke parts of the system.

Converting docx/odt to PDF using JavaScript

I have a node web app that needs to convert a docx file into pdf (using client side resources only and no plugins). I've found a possible solution by converting my docx into HTML using docxjs and then HTML to PDF using jspdf (docx->HTML->PDF).
This solution could make it but I encountered several issues especially with rendering. I know that docxjs doesn't keep the same rendering in HTML as the docx file so it is a problem...
So my question is do you know any free module/solution that could directly do the job without going through HTML (I'm open to odt as a source as well)? If not, what would you advise me to do?
Thanks
As you already know there is no ready-to-use and open libs for this.. You just can't get good results with available variants. My suggesition is:
Use third party API. Like https://market.mashape.com/convertapi/word2pdf-1#!documentation
Create your own service for this purpose. If you have such ability, I suggest to create a small server on node.js (I bet you know how to do this). You can use Libreoffice as a good converter with good render quality like this:
libreoffice -headless -invisible -convert-to pdf {$file_name} -outdir /www-disk/
Don't forget that this is usually takes a lot of time, do not block the request-answer flow: use separate process for each convert operation.
And the last thing. Libreoffice is not very lightweight but it has good quality. You can also find notable unoconv tool.
As of January 2019, there is docx-wasm, which works in node and performs the conversion locally where node is installed. Proprietary but freemium.
It appears that even after three years ncohen had not found an answer. It was also unclear if it had to be a free (as in dollars) solution.
The original requirements were:
using client side resources only and no plugins
Do you mean you don't want server side conversion? Right, I would like my app to be totally autonomous.
Since all the other answers/comments only offered server side component solutions, which the author clearly stated was not what they wanted, here is a proposed answer.
The company I work for has had this solution for a few years now, that can convert DOCX (not odt yet) files to PDF completely in the browser, with no server side component required. This currently uses either asm.js/PNaCl/WASM depending on the exact browser being used.
https://www.pdftron.com/samples/web/samples/viewing/viewing/
Open an office file using the demo above, and you will see no server communication. Everything is done client side. This demo works on mobile browsers also.

extjs application architecture

I am developing a extjs application, and I am just a starter.
It's quite different develop mode for me, and I feel puzzled.
My first question is about client-end architecture, I'm developing a little app now, so I wrote all js codes in only one html file, what if I need to develop a huge app?
like this: [Article Manage(leaf in tree)] -> [CURD List(Data Grid)] -> [Edit Article(Dialog Box)]
There will be lot of leaf in my tree, so there are many XXX Manage.
What should I manage my client-end js files(file structure or something else), and how to load these files dynamically? Is there any exists demo?
um.. maybe what I really want to ask is:
How to put my code for every module into different js files and 'include' the dynamically?
I've got the answer, just use loader property of a container component, this method fit me well. Thanks to all of you.
There are no patterns set in stone, but here's one way to Write a Big Application in Ext 3.x.
Another good resource for ideas, generic to JavaScript, is Nicholas Zakas's video on Scalable JavaScript Application Architecture on YUI Theater.
In my mind the big things to do are:
Write standalone components (think: UI container, data structure, etc) with no dependencies to other components on the page.
When you want to two components to interact, have their parent container wire them together.
Have some kind of logical directory structure for development (doesn't matter what exactly), splitting out each of your "components" into its own file -- even if you plan on combining them into a single file for deployment.
Not sure if I correctly understood your question, but I'll try to answer. For bigger applications use MVC pattern which allows you to split your application to components such as Stores, Controllers, Views etc. Then you can easily send data from server in JSON for example (using server-side technologies - php, java,...) and read it by Stores proxy. If you look into Samples & Demos they're also loading some bigger structures using php script which returns JSON.

Categories