Detecting system locale(language) in html - html

I have a web site working in English. I want to localize the code such that the html text (currently hardcoded in english) can be changed according to system language.
For example:
<section id="myInfo" data-bind="with: My.ViewModel.Testing">
<header>
<h1>Test Case 1</h1>
</header>
....
</section>
The text "Test Case 1" needs to change to the system specific language. Any hints on how I could achieve that?

There is no way to detect system locale in HTML. Besides, what would you do with the information? There are no tools in HTML for changing text content.
In JavaScript, there are ways to access the system locale in some sense. But this is still wrong approach to localization. Localization should be performed when the page is generated, possibly in response to a user request that specifiess the preferred language.

Figured that one of the ways to achieve this is using the resx files to replace the text and use fmt namespace from html code:

Related

Making "personalized variables" in html

Okay, my english is not the greatest so I apologize in advance. Question is really stupid and I dont know how that is called but I will try to explain it here better. So I am making a template for one restourant and menus are changing every week. So is it possible to write paragraphs somewhere else ( in separated place (external or internal)) and then "call them" somewhere in .html.
Example. making methods in C# and then calling them anywhere when we want to
In my opinion the simplest method will be to use php.
Then in place with menu you can only use something like this:
<?php inlcude('menus/file.php');
And on server create a folder menus where you wil put php files with html.
All files can be simple html. There is no need to learn php just in place you want to call a file use code i placed earlier.
HTML doesn't have a good way to achieve this (although iframe exists).
This sort of thing is generally handled by software that generates the HTML, either when the page is requested (via something like the very basic SSI support in some webservers to full on server side programming (which you could use C# for)) or at publication time (via a build tool such as Gulp).
You could use jQuery to achieve it (if it is a simple website and simple menu), read more the related function on http://api.jquery.com/load/
You may also read a simple here: HTML File including another HTML file
I may also include a very basic example for you
main.html
<body>
<header>Some header</header>
<content>
<main class="the-menu"></main>
</content>
<script>
$(".the-menu").load("menu.html");
</script>
</body>

CKeditor rich text editor displaying html tags in browser

I've just installed CKeditor rich text WYSIWYG editor on a site I'm building and it seems to be working ok except for the fact that it inserts text into my mysql database as encoded html rather than regular html and then when the browser outputs this text it converts the encoded data into regular html that then displays in the browser showing the html tags and none of the styling!?
eg I type:
"This is text"
into the editor and it then inserts
<p>This is text</p>
into the database. Then when the page is called the browser converts the above and outouts the following on the page:
<p>This is text</p>
obviously I just want "This is text" to display on the page.
Does anyone know why this is happening/how to solve it please?
Any suggestions would be most welcome.
Cheers
If you don't want CKEditor to create paragraphs for you, set config.autoParagraph to false. Additionally you may want to change enter key behaviour with config.enterMode set to CKEDITOR.ENTER_BR.
And regarding disappearing styles...
EDIT: OK, it seems I missed your point.
So your website is displaying HTML markup instead of HTML while rendering out what you typed?
Then the problem is your server side rather than CKEditor. You can verify in your console that CKEDITOR.instances.yourInstance.getData() yields the correct, unescaped HTML:
<p>This is text</p> // Right!
If it is so, and I strongly believe it is, CKEditor's just fine and this is your server app that is converting special chars into entities (i.e. like PHP htmlspecialchars) while saving to database. You didn't mention what kind of framework/language you use there, so I can just tell you that it is to secure user input to prevent cross-site scripting, breaking layouts etc. and all popular frameworks allow you to disable that feature for a particular field. Simply refer to documentation.
Modern templating languages tend to autoescape html input. For example, in DTL it would be displayed correctly in the template by simply using
{{ object.field_name|safe }}
This is a desired action, since user input is considered untrusted and may be considered malicious.
The browser is not parsing HTML, so on the page displaying (or in the php file) try using {! !} instead of {{ }}.
If you are using laravel, then you should use {!! $variable !!}.
For Laravel 7, 8, and 9 - foreaxample if there is a varable called- $student
and student varable holds "This is Text" in paragraph you must call the varable using singla culy brace front and back, inside two

Use HTML documents like stylesheets

i'm making a website for someone who is not particularly well acquainted with html and i want them to be able to edit the content of their webpage just from a blank text/html file (or easier method),
i'm wondering if there is anyway i can just have a text document but save it as a html which i could load within <p></p> tags
for example: maindocument.html
<html>
<body>
<p id="text">....[someway of getting text from textdocument.html (or .txt)]....</p>
</body>
</html>
textdocument.html (or.txt)
"text to go within p tags"
you can do this with css style sheets and scripts so is there a way to do this with basic html?
If the web server is running Apache you could use SSI. The files will need to be in .shtm or .shtml format.
Then all you do is
<p>
<!--#include virtual="paragraphs.txt" -->
</p>
I'd usually just use PHP includes though.
If a .txt file is enough, I guess you could use an iframe to load it:
<iframe src="myfile.txt"></iframe>
But if you want rich editing, I'd suggest implementing a WYSIWYG editor and saving it somehow.
The simplest way is to use server-side includes if they are available on your server: http://httpd.apache.org/docs/2.2/howto/ssi.html
Otherwise you might consider using a scripting language like PHP and include the file, like:
<?php include("textdocument.html"); ?>

Gmail iOS App uses custom html tags - any info?

So I was looking through the Gmail iOS App (2.0.1) and saw some included html files like calendar.html:
<h1>
<?cs #trans description Title for screen in welcome sequence describing the
ability to immediately act on calendar events. (Maximum characters: ~25) ?>
Instantly RSVP</h1>
<p>
<?cs #trans description
Reference to being able to receiving emails for calendar events and being able
to act on the events immediately.
(Maximum characters: ~100 depends on line breaks) ?>
Respond to Google Calendar invites right from the app.
</p>
I was wondering if anyone knew what the ?cs tags were for. I did try googling it but I couldn't find anything. Maybe its an internal google thing? Any info would be nice. I'm just trying to learn about iOS/Google programming style.
<? … ?> is an XML processing instruction. They are not document data, but are intended for the underlying XML engine.
Typically processing instructions are used by an XML engine as a way of embedding control flow (<? if test="condition" ?>) and commands (<? echo "string" ?>) into the XML document.
Here it looks like cs is a kind of meta command. cs #trans description appears to be a label for for some kind of user help.
I'm sorry it doesn't directly answer your question, but a better understanding of the form might help you learn more about the function.
My guess would be that those bits of text inside the <?cs> tag are used during development by an internal Google localization tool to explain the purpose of the following text to a translator. They are probably not displayed or used anywhere in the running application.

Localizing a Google Chrome Web App

I'm trying to add localization support to a Google Chrome Web App and, while it is easy to define strings for manifest and CSS files, it is somewhat more difficult for HTML pages.
In the manifest and in CSS files I can simply define localization strings like so:
__MSG_name__
but this doesn't work with HTML pages.
I can make a JavaScript function to fire onload that does the job like so:
document.title = chrome.i18n.getMessage("name");
document.querySelector("span.name").innerHTML = chrome.i18n.getMessage("name");
but this seems awfully ineffecient. Furthermore, I would like to be able to specify the page metadata; application-name and description, pulling the values from the localization files. What would be the best way of doing all this?
Thanks for your help.
Please refer to this documentation:
http://code.google.com/chrome/extensions/i18n.html
If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. That is the only way you can do it.
chrome.i18n.getMessage("name")
It isn't inefficient to do that, you can place your JavaScript at the end of the document (right before the end body tag) and it will fill up the text with respect to the locale.
Dunno if i understand exactly what you are trying to do but you could dynamically retrieve the LANG attribute (using .getAttribute("lang") or .lang) of the targeted tag and serve accordingly the proper values.