I want to provide different translations on a single page website. Is it a good idea to translate every text entry using this approach (pseudo code):
html
<p id="my_text"></p>
js (jQuery)
function init(){
$('#my_text')[0].innerHTML(isEnglish ? "Hello" : "Hallo");
}
If this solution has any disadvantages or will lead to issues, please let me know which (simple) solution is the better option.
In my opinion, this is going to be tedious for a long passage.
I would suggest you use a bing translation API
Related
I am working on a custom plugin for esri web-app builder and I noticed two things in their dojo widget that I cannot really understand.
there is a cahce property that has a lot of function under it and also this kind fo property "url:widgets/PrintAndShare/templates/Print.html" which is legal by JS, but why using that instead of the standard dojo/text!.template, I see that the template itself is still loaded ( but ignored) - so the question is -how exactly that cached property works.
the main question is - these properties have html encoded in very specific way for example
<div class="gis_PrintDijit">
encoded like this
\x3cdiv class\x3d"gis_PrintDijit"\x3e\r\n
how do I achieve this kind of encoding ? with online tools or even better with some automation, for now I just use manual char replacing but it is really not efficient.
Thanks you all
I do not know if there is a better way.
A simple workaround can be to use encodeURIComponent and then a replace:
var t = "<div>test ok: 100%</div>";
console.log(encodeURIComponent(t).replace(/%/g,"\\x"));
Good day,
I am just at the "dawn" of web design and I haven't been able to find a good answer to
this question as of now.
"Let us say I would like to create a website that has 3 pages:
1) Index\Home
2) Contact
3) Personal Works
In the personal works section I would like a list to appear which is ok, I would just go
<ul><li></li></ul> etc etc
Now Let us pretend that in the <li></li> I want to put names of poems I have written as per my personal website portfolio. Each li would then send you to the requested poem.
All is good.
Now to the real question: I assume that creating 150+ html files for each single poem is a suicide, useless and dumb. That said, how do I actually do it?
I don't need you to do hard-coding for me. If you could just explain a little bit and maybe post a few tutorials\examples, Id be glad.
Love you.
That is where a server-side language is used. You use the server-side language to read some parameters and then provide the solution depending on the condition.
I would recommend you to use ASP.NET, or you can use PHP or some other server-side languages. But my preference is ASP.NET.
Solution:
You can try something like, one single page named: poem.cshtml (cshtml is a file, which accepts C# code alongwith HTML). Then inside the page you show the code depending on the URL. Lets say you're having a simple poem of Twinkle Twinkle Little Star. Then
http://www.example.com/poem/twinkle-twinkle-little-star
Now you can get the poem name using:
var poemName = UrlData[0];
Then use an if else block to do this:
if(poemName == "twinkle-twinkle-little-star") {
/* write that poem
* or by using else block, show other poems */
}
This is easy to understand and learn.
You can use Database to save the Poem and show it using ASP.NET. You need to learn alot.
Start Learning
http://basicsofwebdevelopment.wordpress.com (Beginner's Site)
http://developer.mozilla.org (To learn HTML, CSS)
http://www.asp.net (Official ASP.NET website)
What you need depends on how all that would be used. You may really need to use server-side language, or if content is generated on client side, respective array of li would be generated using javascript
For a newbie PHP would be the easiest server side language to learn, mixed with javascript, ASP.NET is also a nice language but a bit more of a learning curve although if you have any C# experience learning it would be easier.
I would like to use the Glimpse client viewer in a web application in order to render some JSON. I am unable to use the Glimpse server implementation on the site in question. However, I can implement my own IHttpHandler to render the information using the Glimpse JSON format.
Has anyone done this and posted details on how to do it? If not, can anyone tell me the steps required to get this up and running? Alternatively, are there any other similar viewer frameworks out there?
Note: I am poking around the source and have seen the client js etc. I will continue down the source hacking route, but was hoping someone may have some shortcuts for me!
As Nik said I would be interested in what you are trying to do. But in the mean time the best place to look is http://getglimpse.com/Protocol.
If you look on this page you will see that we have built a protocol tester. This allows you to put in any JSON and see the output.
If you want to do this yourself, have a look at http://getglimpse.com/Scripts/Protocol/LayoutExample.js and you will see how we do this without using the whole of Glimpse.
You will see that we are doing something like the following:
var data = { test : 'test', hello : 'hello' };
var html = $Glimpse.glimpseProcessor.build(data, 0, false)
$('.panel').html(html);
I know this isn't as nice as it could be but it wasn't designed with this in mind.
We are currently working on refactoring the client code to make this all better.
We haven't really documented all of this yet.
Your best bet is to look at first glimpse javascript file that gets rendered to a page - it is the data file. If you can output data in that format, which is basically just one object of key value pairs, then the client will pick up the data and render it.
You might also want to look at the Glimpse.PHP implementation, since they'vve had to do the same thing you are.
Good day folks,
Recently I worked with EE and was quite impressed with they small but flexible url segment feature.
So I though it will be useful in JS development and what to hear your thoughts and ideas how it can be done.
Who don't know, here is little explanation:
EE url segment is used to compare url part value after each "/" and they have segment1 "/" that is main url part value after domain name, segment2 "/../" that is next url part value and etc.
Why I am interested in it?
I want to create one JS file and call for parts in it only on pages I want.
For example if first url segment is empty I will call for JS that is for home page.
If first url segment is /contact I will call JS for contact page (validation, etc.).
If second segment is /get-to-us (/contact/get-to-us) I will call only JS for google map, etc.
So, the question is, how to take and compare segments with jQuery.
P.S. Explanation on EE website http://expressionengine.com/wiki/URL_Segment_Variables/
This seems like far more work than you need to do. Why not just load distinct JS files conditionally in your template?
{if segment_1 == 'contact' && segment_2 == ''}
<script type="text/javascript" src="/assets/js/validation.js"></script>
{/if}
{if segment_1 == 'contact' && segment_2 == 'get-to-us'}
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="/assets/js/map.js"></script>
{/if}
Etc...
I know this doesn't answer your specific question, but it seems like the cheaper way to accomplish your goal.
I agree with D-Rock. The idea to dynamically pull in JavaScript based on the URL seems like a lot of work for very little return on investment — not to mention increasing the complexity and maintenance of the site.
However, to accomplish your goal, there are a few ways to approach this:
Embed the JavaScript for the current URL into that page's template (no conditionals needed, though not all of your JavaScript is in one place).
Reference a site-wide embed/snippet on every page, then use conditionals to show only what you need (as suggested by D-Rock).
Depending on your needs or requirements, you may find it easier to simply include all of your site's JavaScript into a single external file and allow the browser to download and cache the file. This has the benefit of being extremely easy to maintain, and will decrease subsequent page loads (since the browser can load the file from its cache).
However you plan to use conditionals, when choosing between Simple or Advanced Conditionals, use simple conditionals before advanced conditionals — this is a proven performance recommendation.
I currently am working on a little app that requests user info from my server and displays them using a special template.
At first, I just hardcoded the little snippet in jQuery:
$("<li><div class='outer'><table><tr><td rowspan=2 class='imgcontainer'><img class='thumb'/></td><td><span class='username'/></td></tr><tr><td><span class='name'/></td></tr></table></div></li>")
I clone it several times.
It's ugly and I want it to have syntax highlighting and whatnot, so it would be better for me to have it in the HTML file itself.
Also, it will make merges easier so somebody can just change a line or two.
Is there a pattern for this? Am I OK putting it in the HTML file that I include this JS in (there's only one), and making it hidden using CSS.
The third option I thought of is just creating a separate HTML file and having jQuery request that from the server to keep it separate. Is this technique used much?
Also, is there any term I can use to describe what I'm doing? (It's harder to ask a question for a concept I don't know the name for)
I gave a similar answer on SO earlier today. What you are looking for is called micro-templates. John Resig posted this on his blog. Essentially you can get a json dataset and apply a template to the data to create html and update the DOM.