Change input language according to user specified language - javascript

I am trying to type into the language specified by the user according to the language selected. I got the following URL for the same but it supports only Farsi.
Change input to Farsi.
Please can anyone suggest me how to get this done or are there any online sources by which the languages be converted to js files to be referred ?

Related

Search Engine Result Page Url includes Search Value

I am trying to create a new language translator engine (only two language available a<->b) its just to learn PHP & Mysql etc. a little bit better. Now I have a search form where a user can enter a value and a php code which check if that word is available to give the result in an antoher fix language. But a user enter a value ex. "food" and submit it then the url should look like that
https://domain.com/search/food
How is it possible to get a permalink without using a CMS. I only want to do all as static page and PHP, MYSQL AND JS nothing more if possible
I see that already on a few pages but not sure how to do that and hope you could give me only a few advices.
Unless you want to store a file for every single possible word, this isn't possible with straight PHP, you will have to leverage your server's functionality.
Assuming you are using Apache, check the documentation for mod_rewrite.
But, you could also simply use URL parameters, which is easier and will act pretty much the same in practice. e.g.:
https://domain.com/search.php?term=food
PHP:
$_GET['term'] // => "food"
http://php.net/manual/en/reserved.variables.get.php

How to detect web page language with no lang attribute

I have an extension and need to detect the language of webpage. I learned I can obtain "lang" to get the answer. However, lots of webpage don't have "lang" attribute in .
In this case, how can I know what language of the webpage is?
Thank you.
The language is set by the user's browser in the navigator object's language property. Here's an explanation from W3Schools.
var lang = navigator.language;

Set language variable using html/js

I am currently creating on online version of a magazine. The magazine is made up of a series of html5 pages. On each page, the user is provided the choice to choose language,"En/Fr".
I would like to know how i can set the language to the chosen one for the whole magazine. For example, suppose I am on page1 and 1 choose lang 'Fr', the other pages too should be loading in Fr. And now, on page20 I choose lang 'En', all the pages should load in 'En'.
Is that possible using html/js??
Could you provide me with a solution.
Thanks
This solution can't be achieved using pure javascript and html, as the variables will be lost when the page is reloaded.
You may like to investigate a solution using cookies.
For your example.
To set language:
$.cookie("language", "fr");
To read language from cookie:
$.cookie("language")
To delete language:
$.cookie("language", null);
There are a few options: using a cookie, using sessionStorage or localStorage, and including language identifier in URLs (path part or query part). There is insufficient information (no info about server-side technology used etc.) to suggest a particular approach. In any case, if you want the pages to be found via search engines, each language version should have a URL of its own.

Javascript - Upload file content type validation

How to validate the content-type of a file before uploading using JavaScript? I'm not asking the extension validation. I want to validate pdf,plain text and MS word files.
I'm using a django forms.ModelForm to pass file upload widget to html. I couldn't achieve this either on server side. Here is that question,
Django - Uploaded file type validation
Maybe but it won't give you any form of security because an attacker could use other means to upload files thus circumventing your validation.
To check the file type using the extension (which is very insecure since it's dead easy to manipulate it), you can use JavaScript. See this question: How do I Validate the File Type of a File Upload?
[EDIT] After some googling, I found that the input element has an attribute accept which takes a list of mime type patterns. Unfortunately, most browsers ignore it (or only use it to tweak the file selection dialog). See this question: File input 'accept' attribute - is it useful?
[EDIT 2] Right now, it seems that the File API (see "Using files from web applications") is your only way it you really don't want to use file extensions. Each File instance has a type property which contains the mime type.
But this API is work in progress, so it's not available everywhere. And there is no guarantee that you'll get a MIME type (the property can be "").
So I suggest this approach: Try the File API. If it's not available or the type property is empty, use the file extension.
In theory you could use the File API to read the files.
You would then need to write parsers in JavaScript for the file formats you cared about to check if they matched.

Use bing translator in my website

I recently have come across with a need for some type of "translation"-type that could translate specific text fields or areas to other languages.
I want when user will write texts in **<input type="text" id="texttotranslate"/>** html control and after space the text should get converted to local language i.e. Hindi, Arabic Finnish
I am not sure if something like this even is out there - but I thought this might be a good place to ask.
Link 1
I came accorss this links as well but i want it Javascript / ajax solution to get it done
Link 2
I went through this and create my APPID
I am getting link 1 working in my C# console application but
i want a javascript solution for the same. ie. when i write a word in the text box it should get converted to local language i set .
if you are using Bing translator in your website, then there is no need to write any code in C#. You can use the Bing URL directly to translate the words.
Please refer to the following URL: http://basharkokash.com/post/Bing-Translator-for-developers.aspx
One option would be to put the Microsoft Translator widget on your site (http://www.microsofttranslator.com/widget). Mark up the fields that you don't want translated using the class="notranslate" tag.
Alternatively, if you want to use the API, I recommend following the tutorials here:
http://blogs.msdn.com/b/translation/p/gettingstarted1.aspx
and
http://blogs.msdn.com/b/translation/p/gettingstarted2.aspx
While the second link does it in ASP.NET, instead of JavaScript, it should give you a rough idea for how to do it. At the very least I recommend getting your access token server side, using ASP.NET, PHP or something similar, so your Client ID and Client Secret are not in-the-clear on your site.
Finally, take a look here: http://msdn.microsoft.com/en-us/library/ff512385.aspx, for the MSDN documentation on the AJAX API, including how to access it using JavaScript.

Categories