im just testing Hype. So far im quiet impressed. And now im wondering if there is a possibility to setup text and buttons multilanguage. Like adding countryflags somewhere on stage which lets the user choose the language.
Is this possible to be done without putting any different language stuff into another scene but just by replacing the text on textboxes and buttons?
And it would be even helpful if I could enter several different text versions and somehow select which version to use in the export step. It doesn’t has to be dynamic.
But I want to avoid, duplicating animations just to have different texts, which will become a maintenance hell.
It’s very easy to accomplish, for example a button: just duplicate it and put another language in it. Group all these buttons with different languages and use this group for the onclick event and animations. Set all buttons to invisible and use a JavaScript to make the selected language visible on scene load. I would recommend not to use the unique id, but use the classname instead.
You can use a script which detects the browser language.
I am thinking that making duplicates of elements will be a pain to layout and could bog down the page load.
You would also have to hide and show them with javascript. So my take on this is to:
To have a function run on scene load that sets up some global variables that represent the language text for each element.
i.e:
//-- Main Text
window.english_mainText = "Is this possible to be done without putting any different language stuff into another scene but just by replacing the text on textboxes and buttons"
window.spanish_mainText = "¿Es esto posible por hacer sin poner ningún diferente material idioma a otro lugar, pero simplemente reemplazando el texto en cuadros de texto y botones"
//-- Buttons
window.english_eleButtOne = "Element 1"
window.spanish_eleButtOne = "Elemento 1"
We will give every element that needs to change a class name and a unique id.
i.e
langIsChosen for the element 's class name mainText for the element’s id
When a language button is clicked:
Each language button uses the language name as it’s unique id.
i.e spanish, english are used as ids
When clicked a javascript function is called and the buttons id is obtained.
We than get an array of all the elements with the class name (langIsChosen) that an element has if it’s text should change.
We combine the language button id and the element ids and change the innerHTML.
I have updated this example to show local storage use. And put the language text strings into object arrays.
The language text strings all have a key using the language code. i.e
en = english
es = spanish.
This just makes things a little bit simpler in the code for choosing the language and we can expand the codes use as shown with the language badge which shows the current users choice.
I have just used the text code in the badge but now it is simplified gives possibility of using JS conditional coding to display a language image.
Well, as said, I don’t think that doing it dynamic makes any sense.
This is a fundamental feature Hype needs to support. I prefer a way where I can generate static versions for the different languages with one click. “Export to HTML5” and than get back X versions. No coding to keep in sync with my animation changes etc.
The JS solution works, sure, but it’s way to complicated for the problem.
My understanding of the original question is , it is about having an easy way to build a setup where the end user not the developer can select a language from a button on the site… This has to be a dynamic process
Although what you refer to is similar It may be better if you create a separate request RE: static language export.
Thanks for your feature request. We don't get many requests for multilingual element support, so for now @MarkHunte's example is a great way to accomplish your and @Tomi's goal.
Hi Guys, I was able to do this with Edge… I did some tests and was able to port over the code to Hype and it works. You store translations in a text file and based on the URL parameters you show the correct text version… For example,
One issue you may run into with this approach is that some languages take up a lot more space than others, which will impact on the look of the final product. Depending on the languages you need to translate for, creating separate scenes might be a better approach.
Note: Initially thought of this and wrote my code but then did a search on the forum for hash to see if it had been discussed before. It had in @Daniel 's excellent thread where I nicked the .substring(1); bit
Mmm, thought I had this working but not quite. Will show what I did in Edge Animate that works.
If anyone can help port it to Hype I think it would be a tremendous help for everyone.
So the way I had it setup was keep all my translated in a separate javascript file to separate content from design.
The files looks something like this:
In my document I would create corresponding labels that would contain the translations.
Then when my Edge document would load (compositionReady) I would do the following.
First, I would run a script that to create a variable from the the URL parameter.
sym.getParameter = function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
var Lang = sym.getParameter('lang');
Then lastly, I would easily tell Edge what I wanted translated by the following:
OK, got it working. See attached source files. You can use this method to localize any text and keep content separate from design. Localize.zip (23.6 KB)
Just been making a personalised Christmas card to people. Yes one card to fit all. I’m lazy and find this more fun than writing out cards. Oh and help save the trees…
But this whole idea is really great for them.
Using a version of the langTest2.hype.zip posted above, I am able to change the creating using the above methods, love it.