Webpage-text translation on client-side (without internet connectivity) - javascript

I need a web-application to be translated from English to Portuguese.
Since the servers on which this application runs have no internet access, is there a way to achieve this without using a 3rd Party API. Is there a JS Library that can translate from say Language A to Language B on the client side ?

You can definitely use Java Script for that.
The library well known for translations is the i18next
You can integrate with jQuery, but I strongly recommend you using something like AngularJS or Mustache for customise your template.
If you choose use AngularJS you can have a different JSON file with your expressions, and depending on the language you are navigating, loads a different JSON file, like:
en.json, es.json, pt.json
You can use JS Cookies for saving the language as same you would do with any backend language.
Mustache is used to create templates front-side with double brackets {{custom_text}}. AngularJS uses the same idea.
The only issue if you want to use AJAX. Read more about Google Chrome --allow-file-access-from-files disabled for Chrome Beta 8

Related

How can i integrate C# code into an existing Javascript website (Angular)?

We have a large ecosystem of Javascript websites, actually Angular, that we don't plan to rewrite in c# any time soon. So the goal here is to be able to use a vendor dll in our javascript to add new features. This is a proprietary system, we don't have any alternative, either we use their dll, either we don't have the feature. I'm putting a lot of hope in webassembly here because this looked like the silver bullet to use that dll without having to rewrite the whole project in a new language.
Problem: all the examples I can find are more about using Blazor to write a website or call javascript from Blazor, I can't find anything to include some ad-hoc C# code into an existing project. I would have thought it would be a great use case though because being able to leverage C# threadpool on a webpage sounds pretty good to me!
Anyone has done something similar or know some examples/tutorials I could follow?
As Tuan says Angular and C# don't really live together in the way you suggest.
I would say there are 2 separate approaches here.
Have an C#.NET MVC app but adjust the routing so the Angular App Handles some pages and the .NET app handles others. This is OK but there are so many pitfalls such as the fact that you can not share bundled CSS and JS or maintain the structure of your Angular controllers (amongst others).
A better way would be keep your lovely Angular app the way it is but have a separate Web API application/project and use the angular app to call the dll (reference in the project) within the correct context as a REST API (via a simple POST or GET call).
It's not too clear exactly what you want to do when you say "... able to use a vendor dll in our javascript to add new features ..." but you can find info on writing and implementing C# as a Web API in .NET core here
https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio

deploying a javascript 3rd party library (requirejs/grunt)

Our team is building a javascript library that enables other web apps in our company to consume and insert data into our app, using widgets we built with angular directives.
So we got our own app (that could be used independently), built with MVC .net (in visual studio), and with angular. And also we are producing sort of a javascript library that other apps can use and insert widgets (that are connected to data from our app through ajax calls).
We are really struggling with our deployment proccess. We need the following to happen:
Concatenating and minifyinh our javascript, and in the right order.
Compiling less, and concatenating and minifing css.
Handle external dependencies because we are using multiple 3rd party libraries also, which maybe others are using also.
We know about requirejs, but we are not sure it is suitable for a 3rd party sort of library we are building. Also we want to enable loading as CDN, is it still suitable?
We also know about grunt, but we are not using nodejs but MVC .net. Is it relevant?
We would appreciate your input! Thanks!
I would strongly recommend using a build tool such as Gulp or Grunt, both of which can easily handle the requirements you've given. An added benefit is both can be set up to initiate parts of the build process as files are saved, freeing developers to use any editor they want instead of a particular IDE.

how write text/template in a file and include it to project

I use script type="text/template" for my project and I use a lot of templates, I want write my template in foreign file and include it to my html
If its possible , what type of file must i use and how must write it ?
In a pure JavaScript/HTML environment, you can't easily.
Your choices are:
Use some kind of JavaScript template library
I'm only familiar with Durandal that uses the Knockout engine.
AngularJS seems to be another popular choice.
Most of these packages include far more than just templates and may be overkill.
Use a server-side template package
PHP is a popular server-side tool.
Some HTTP Servers support Server Side Includes, but these are so limited I couldn't actually recommend them.

Converting remote RRD to JSON format

I have a project wherein I need to access remotely hosted RRD files and create a highly interactive dashboard to visualize the data (most likely using Rails/Flot etc..)
I've looked into projects such as RRDTool and Jarmon (which seems to be collectd specific) and was wondering if there was a proven way to get the data from the rrd files into a format I can use on the javascript side of things. I intend to have this running on a fairly simple heroku instance, if that's any indicator of my server restrictions.
Thanks so much,
Nader
Have a look at rrdtool xport called on the command line it can produce json for you or when called via a scripting api you get the raw data which you cann then easily convert to json using your scripting language.
HTH
tobi
You need JavascriptRRD:
http://javascriptrrd.sourceforge.net/index.html
As the name implies (Javascript RRD), javascriptRRD is a javascript library for reading and interpreting RRD (Round Robind Database) files from both remote Web servers and local file directories. It uses AJAX-like techniques, but without any code being run on a remote Web server; i.e. it provides a purely client-side access to RRD files.
The javascriptRRD package provides the basic RRD reading libraries, as well as helper libraries to make displaying of RRD files easy with the Flot library.

Edit a file using javascript

I need to edit an xml file using javascript. Now I'm involved in a project of online testing.
The question.xml file is already in the project folder.
In that i want to add or edit the questions(only using javascript). I'm able to bring the particular content through ajax, but I am not able to edit the file.
Javascript can't write to a file. The best you'll be able to do is get Javascript to read and edit the XML then post that data to a server-side script to write to file.
Until now, Google Chrome is the only web browser that has a functioning implementation of the FileSystem API, therefore, it may allow you to save files locally using only Javascript.
Obviously, for security reasons, when writing files to the local file system, the user must explicitly allow it.
A working tutorial: http://www.html5rocks.com/en/tutorials/file/filesystem/
Nickf is correct. The reason Javascript can't write to a file is because it is a Client-Side language. Javascript will never have permission to write a file because it has to operate inside the browser sandbox.
You will need to use a server-side script (.NET, PHP, ColdFusion, etc) to write the file.
If you are willing to use Google Gears, you get a sandbox on the client machine on which you can write files.
Javascript has no built-in file I/O (a.k.a. you can't do it with JS alone)
Instead use some kind of server side language such as PHP or ASP.NET in conjunction with Javascript's AJAX functionality.
Look over Adobe's Flex development system. There are ways you can use it to build an app that runs in the browser (or not) and can access the filesystem (Windows/Mac/Linux). It's programmed in ActionScript, a dialect of javascript; and can interoperate with javascript in the browser.

Categories