I am recently working in a project. There I need to convert language from English to Japanese by button click event. The text is in a div. Like this:
"<div id="sampletext"> here is the text </div>"
"<div id="normaltext"> here is the text </div>"
The text is come from database. How can I convert this text easily?
Assuming that you have both the English and the Japanese version in the database, you can do two things:
Use AJAX to load the correct text from the database and replace the contents of the div. There are tons and tons of tutorials on the internet about AJAX content replacement.
Put both languages on the website and hide one using CSS display:none. Then use some JavaScript to hide/display the correct div when a button is clicked.
The first is technically more complex but keeps your page size small. The second one is very easy to do, but your page size is larger because you need to send both languages.
If the div is small and there is only one or two of these on the page, I recommend number two, the CSS technique. If the div is large (i.e. a complete article) or there are many of them then use the first method.
If you mean translating the text, you cannot do it easily. To get some idea of the best attempts that software can make at translating natural languages, go to Google Translate or Babelfish. It's not that good, but it's sometimes an intelligible starting point.
If you just mean setting the language attribute on an element, then assign a new language code to the lang property of the div element object.
document.getElementById("normaltext").lang = "en-US";
I don't know the language code for Japanese; possibly ja-ja.
Assuming your literals have an id in your database you could put that id as a class in your div. Then with jquery fetch the ID, send it to your Ajax back-end and fetch the translated one.
First, if you have the texts in a database it really doesn't matter if you render it in divs, tables or whatever.
First you need a php api for some translation service. Here is just an example that might give you some ideas.
$textArray = getTextForThisPage();
?>
...
english_to_japanese($textArray["text1"]);?>
...
Related
In every column there should be a print option. When a particular option is clicked, it will be printed in a certain design or format, but not all the data at a time in PHP MySQL. If anyone knows how to do this, please help me.
As per I understand , you want print button or a link for print. So use this two method
<input type="button" onClick="javascript_print_function">Print
Print
One way would be to have the "print" button invoke a new window which contains just the single row of data, then print that. Maybe that can call print() onload.
Trying to have all the print buttons on one page, and have it select a one from a selection of special print.css file is probably possible, but I have never seen this being done, and sounds as if it could get messy if you have a variety of pages to cater for.
Google multiple print css files suggests some ways of doing this, but I suspect it would be easier to pull off using divs instead of tables.
Does anyone know a clever way to create even columns of text using php?
So lets say I have a few paragraphs of text and I want to split this into two columns of even length (not string length, I'm talking even visible length).
At the moment I'm splitting based on word count, which (as you can imagine) isn't working too well. For instance, on one page I have a list (ul li style) which is increasing the line breaks but not the word count. eg: whats happening is that the left column (with the list in it) is visibly longer than the right column (and if there was a list in the right hand column then it would be the same the other way round).
So does anyone have a clever way to split text? For instance using my knowledge of objective c there is a "size that fits" function. I know how wide the columns are going to be, so is there any way to take that, and the string, and work out how high its going to be? Then cut it in half? Or similar?
Thanks
ps: no css3 nonsense please, we're targeting browsers as far back as ie6 (shudder). :)
I know you're looking at a PHP solution but since the number of lines will depend on how it's rendered in the browser, you'll need to use some javascript.
You basically need to know the dimensions of the container the text is in and using the height divided by the text's line-height, you'll get the number of lines.
Here's a fiddle using jQuery: http://jsfiddle.net/bh8ZR/
There is not a lot of information here as to the source data. However, if you know that you have 20 lines of data, and want to split it, why not simply use an array of the display lines, then divide by two. Then you can take the first half of the PHP array and push it into the second column when you hit the limit of the first.
I think you're going to have trouble displaying these columns in a web browser and having a consistent look and feel because you're trying to apply simple programming logic to a visual layout. CSS and jQuery were designed to help layout issues. jQuery does have IE6 compatibility.
I really don't think you're going to find a magic bullet here if you have HTML formatting inside the data you're trying to display. The browser is going to render this based on a lot of variables. Page width, font size, etc. This is exactly why CSS and other layout styles are there, to handle this sort of formatting.
Is there any reason why you're not trying to solve this in the browser instead of PHP? IE6 to me is not a strong enough case not to do this where it belongs.
Hey guys, there is a form where the user select some of his friends and I'm curious on how I can implement a list that searches simultaneously while the user is typing a friend's name and when he selects the name the name is written in the text box(jQuery). And if the user wants to select more than one friend, when I'm inserting the names in the database, how can I separate the names that are written in one input field?
You should take a look at the jquery auto-complete plugin:
http://docs.jquery.com/Plugins/autocomplete
Also, you could separate the names using commas.
Are you looking to write your own plugin or would you like to use an existing one?
If you want something ready made, here are a few examples
if you want something extremely light, only 6kb packed, this one would be the best choice
Autosuggest jQuery Plugin
Older one but still good
Tokenizing Autocomplete
This what already asked here on this site.
Facebook style JQuery autocomplete plugin
The accepted answer cited this jQuery code.
https://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin
http://jqueryui.com/demos/autocomplete/
Although think twice about including the whole jquery ui library for this one plugin
I've implemented this a couple of times, it is not that difficult to achieve decent results and the basic idea that I used was...
1) create an input box.
2) create a div positioned directly underneath the input box.
3) create a jquery keypress handler. if there are more than x characters typed, ajax request.
4) loop through the results, and if they exist, append result divs to the result box.
5) show the result box.
I can dig up some example code if you would like. Not sure what you are talking about with the select multiple, but you could keep a variable of selected, and change the color of the result div when it is clicked on, this way many results can be selected and then processed later.
I'm trying to highlight the selected text contents by the user inside the HTML page I loaded using PHP + XSL transformation.
I have seen some solutions related with highlighting current selected text, but I need to save some information to the database that makes me able to highlight the same contents for future loads of the same page, taking care of all inner elements that the text could have inside.
The idea is simple: simulate when you use a marker inside a book.
Any ideas? Any suggestion will be appreciated.
Thank you in advance.
Isaac
Use AJAX.
http://www.w3schools.com/Ajax/Default.Asp
IMO, DOM location and the STRING range.
something like,
DOM_LOCATION: div[0]>p[2]>span[1]
STRING_RANGE: 2:20
this means that the string user highlighted from the 2nd character to the 20th character of the 2nd span of the 3rd paragraph of the 1st div, which is "monstration of some" from the example below.
<div>
<p>This has no use.</p>
<p><em>And so is</em> this one.</p>
<p><span>This</span> is the <span>demonstration of something wonderful</span>.</p>
</div>
All you need to do is reverse the DOM location and use the range.
This feature might help you.
just add #:~:text=Highlight%20These
try accessing this link for demo
https://stackoverflow.com/questions/38588721#:~:text=Highlight%20a%20text
I had develop an intranet on CakePHP which in one part generates a custom PDF using DOMPDF. The problem is that I have a memo field (mysql text) which I print after getting the result from PHP nl2br function.
The problems is that in some occasions, this text is too long (even on font-size: 6px) and I need some way to make a page break (get again de header, and footer etc)... or maybe a nice way to get a second column to continue with the text inside.
any ideas?
Got this from Google, http://www.digitaljunkies.ca/dompdf/faq.php#page_break . It doesn't solve the secondary question regarding the repeated header and footer, however. Something like http://www.xefteri.com/articles/show.cfm?id=26 might help with that (not recommended).
Is your header just around the memo field? If so you can put your memo field in a table and use a thead/tfoot section for the header/footer. When the table moves to the second page it should be displayed again (though I believe there are problems with tfoot handling).
If these are document-wide headers and footers you could use inline PHP (see also the FAQ). Or, if you're using the latest release (0.6.0 alpha 2) and are up to patching you could add fixed positioning support and use that to create a header/footer.
See the DOMPDF developer site for more information.
If you have a sample document it might be easier to visualize the problem.
You can do it in two ways
One of them is using a section, on pagebreaks, dompdf will repeat the header. You can force a pagebreak using CSS attribute page-break-before:always
The second option is using PHP to draw the header/footer using $pdf->page_text() function like this
http://www.digitaljunkies.ca/dompdf/faq.php#footers