I'm looking to translate a webpage in PHP 5 so I can save the translation and make it easily accessible via mydomain.com/lang/fr/category/article.html rather than users having to go through google translate.
I've found various easy ways to translate text via CURL, however what i'd really like to be able to do is translate an entire webpage but obviously ignore the tags.
The problem is that Google Translate messes up all the HTML tags, class names etc
Does anyone know of a php class that can translate an entire webpage whilst ignoring the tags?
I'm guessing it may be possible via advanced regular expressions or something like that, but i'm not sure.
I can't just curl Google's response as i'll have all the extra JS that they put in.
Any ideas?
I know it's not quite what you asked for, but a much simpler alternative would just be to include the free Google Translate widget on all your pages. That way visitors select the language they would like to view the site in and Google dynmaically does the rest (and persists their selection throughout the site). You then don't need to worry about trying to create and keep updated dozens of different HTML files for every page, each with it's own set of internal links (which, frankly, sounds like a nightmare to maintain).
Related
I'm trying to traverse the whole PhoneGap thing to get a native app up and running. I am completely fine with creating html5 markup for the actual app, what I need help with is trying to pull in dynamic content from a website. In particular, there is some content on our website that also needs to be in the app. We use a program call Expression Engine that handles all of our content. The content that I would need to pull over would be:
Sermon Videos
Sermon Series
Locations
Plain text content
The majority of the app will be local, but there are some dynamic needs as you can see. I've read a couple things that say "JSON" is the way to go, but it looks pretty complicated as I'm not quite familiar with AJAX. Is this the only way or are there any options or resources anyone can point me to that might help. I'm not even sure if that method would work for our website. I appreciate any help you can provide.
They are correct. What you need to look into is AJAX/JSON and how to present your data to your app using these technologies.
Expression Engine would actually be quite a good choice for this as its template system is quite flexible. There are even add-on modules for delivering your content as JSON if you want t go that route.
A quick google led me to: http://samcroft.co.uk/2011/updated-loading-data-in-phonegap-using-jquery-1-5/
It's a bit more than you need since you will have your content in an existing CMS instead of creating a new database to store the data, but the concepts will hold true and I am sure you will be able to use it to find more tutorials that suit you better.
Let's say I have a plain HTML website. More than 80% of my visitors are usually from search engines like Google, Yahoo, etc. What I want to do is to make my whole website in Flash.
However, search engines can't read information from Flash or JavaScript. That means my web page would lose more than half of the visitors.
So how do I show show HTML pages instead of Flash to the search engines?
Note: you could reach a specific page/category/etc in Flash by using PHP GET function, for example: you can surf trough all the web pages from the homepage and link to a specific web page by typing page?id=1234.
Short answer: don't make your whole site in Flash.
Longer answer: If you show humans one view and the googlebot another, you are potentially guilty of "cloaking". If the Google Gods find you guilty, you will be banned to the Supplemental Index, never to be heard from again.
Also, doing an entire site in Flash breaks the basic contract of the web, namely that you can link to specific content from other sites or in emails. If your site has just one URL and everything else is handled inside of Flash ... well, I don't know what you have, but it isn't a website anymore. Adobe may like you, but many people will not. Oh, and Flash is very unfriendly to people with handicaps.
I recommend using Flash where it is needed (videos, animations, etc.), but make it part of an honest-to-God website.
What I want to do is to make my whole
website in Flash
So how to accomplish this: show HTML
pages instead of Flash?
These two seem a bit contradictory.
Important is to understand the reasoning behind choosing Flash to build your entire website.
More than 80 percent of my visitors
are usually from search engines
You did some analysis but did you look at how many visitors access your website via a mobile device? Because apart from SEO, Flash won't serve on the majority of these devices.
Have you considered HTML5 as an alternative for anything you want to do with Flash?
Facebook requires you to build applications in Flash among others but html, why? I do not know, but that is their policy and there has got to be a reason.
I have been recently developing simple social applications in Flash (*.swf) and my latest app is a website in flash that will display in tab of my company webpage in Facebook; at the same time, I also want to use that website as a regular webpage on the internet for my company. So, the only way I could find out to display html text within a flash file is by changing the properties for the text wherever I can in CHARACTER to "Render text as HTML", look for the symbol "<>". I think that way the search engines will be able to read your content and process your website accordingly. Good luck.
As you say that you can reach the Flash page by get variable using page ID or any other variables. So its good. I hope you will add Flash in each HTML page. Beside this, you can add all other HTML contents in hidden format. So the crawlers could reach the content and your site will look-up in Flash. Isn't it?
Since no-one actually gave you an straight answer (probably because your question is absolute face-palm-esque), i'll try:
Consider using the web-development approach called progressive enhancement. Now, it's fair to say that it probably wasn't intended for Flashification of a website, but you can make use of it's principles.
Start with your standard HTML version of your website
Introduce swfobject to dynamically (important bit) swap out the HTML content for it's Flash equivalent
Introduce swfaddress to allow for deep linking into your Flash movies (pseudo-URLs)
Granted, steps 2 and 3 are a little more advanced that how i've described them and your site size/structure/design may not suit this approach, but at least it's an answer.
All that being said, I agree with the other answers/comments about the need for using Flash to display your entire site - there's very very very few reasons anyone would do that, and there's more reasons than already added as to why not to (iOS devices etc)...
Afternoon,
Bit of a tricky question this one, I have a website and need to translate the pages into french, I am using google translate API to do the translation. What I am doing is loading in the HTML templates into a string using PHP and then need to translate the text copy on the pages and then save as for example:
fr_master_header.html
de_master_header.html
The problem I have is identifying the text copy on the page ignoring the HTML, replacing the copy in the extact place and then saving the file with the HTML tags and trasnlated text copy.
Cheers in advanced.
Thinking about translating your application before you write it is going to save a massive amount of time/money. You might be able to go back and fix the HTML, but this is going to be seriously masochistic. You are far better off with the Goolge Ajax Language API if you are adding language support after you've built the app.
I took care of this problem by using variables for every piece of text. Then I check what the language the user wants and I include the corresponding language file. My template system takes care of where to place these variables. These language files look something like this:
$_TEXT['Login']['title']="Enter Username and Password";
$_TEXT['Login']['error']['pass']="incorrect password";
$_TEXT['Login']['error']['name']="invalid username";
The variable name is always going to be the same regardless of the language. This is very scalable, I can support as many languages as Google will translate without making any modifications.
A friend has asked me for help with her website design. Although I know a fair amount about the basics behind HTML, XML, Php, ASP.Net, javascript, etc., I'm not really comfortable sitting down and coding from scratch. All of the work I do is in Java, C++, and so on.
My friend would like to add a vertically scrolling marquee to her site - no problem, there is code for that all over the internet. Here is the tricky part - she would like the text to be dynamically pulled from another website. This isn't like a simple text file, either - it's a list of names from a specific blog post, so there would be a lot of text processing involved to wade through all of the other markup, and extract the relevant info.
The way I see it, here are her options -
1) Write some kind of a perl script or somesuch that is set to run daily. This script will visit the blog and extract the necessary info. It will then update the HTML file's marquee text with its new info.
2) Some sort of active page written in ASP or PHP that will dynamically build the marquee (and the rest of the site) each time the site is visited, basically doing the work of the perl script each time. This seems like it has the potential to be somewhat slow.
Per my understanding, those are her only options. Am I correct? There is no simply way to do this in javascript that I am just missing? I know you can reference an image to be dynamically pulled with the marquee, but this isn't that simple...
Thanks.
EDIT: I guess where I was going with my question was this: Unless I implement this statically, this is going to be fairly involved, right? I believe it is over my head. This is why I would like to simply copy/paste the text list into the html document. It would need to be updated every time the blog does, but that only appears to happen every few months, so that's not a large chore. I realize this is a lazy solution, but this is from someone very inexperienced in web development.
For reference, this is the SPECIFIC blog post which the text will come from, and my friend would ONLY like to display that list of names that begins when you scroll several paragraphs down.
http://truthnottasers.blogspot.com/2008/04/what-follows-are-names-where-known.html
It depends what the list of names looks like, i.e. how much intelligence is needed to parse it. But this could be something that could be fairly easily be pulled, parsed and displayed using Ajax, for example in the jquery flavour.
All the blogs I have ever seen have an RSS feed. Why not just grab the feed?... Google provides javascript that does only this.
Google Ajax Feed API
The RSS suggestion sounds good. If you can't get it in the RSS you could screen scrape the content.
If you could do it with Javascript I think it would suffer the same resource issues as your once a day Perl script and every load asp/php methods since it would still have to fetch the web content by making a call to the web site.
Another option is to use asp.net and enable caching so that when other visitors come to the site instead of getting the page all over again it serves up the cached page. You can set this to cache for 24 hours or so. I'm sure other server languages have similar features. Basically this would be the same as your once a day Perl method but keep it within a web framework.
Another hacky solution would be to use an iframe and frame the content with javascript so that it only shows the content you want to show. Of course you'll have no control over the formatting (background, fonts) of the iframe and if the content gets bigger or changes position you'll have problems.
I am using phpTumblr, a wrapper around the tumblr blog api that allows you to access posts via php.
I want the site to display new posts dynamically, so I am using php to write html code. I find myself writing things like print(blablabla); or print(); ... and so on, and setting the header of the document to text/html, so that the browser would read it as html.
This just seems to me like a kind of ugly hack, and I was wondering if most dynamic pages are set up in this way, or are there different ways to convert php objects(say arrays) automatically into html tags. So far it doesnt seem like there are any.) maybe i have to be using some CMS software?
Any advice would be great.
Thanks
I believe what you're describing is known as a template engine. It essentially separates the logic from the UI, and allows you to write dynamic pages without an excessive number of print or echo statements.
For PHP, I would recommend Smarty, but Google can also help you with finding alternative ones if you find you don't like it.
PHP is a language in which you can do alot of different things and one of them is to send output to browsers. So if you want to print an array as HTML code , write a PHP function for it. PHP has NOTHING to do with HTML tags directly.
Like the above post mentions you can use Smarty templating engine ... BUT then you will need to learn the smarty language to print the array :)
All scripting languages work in this way. So lets say if any xyz language supports a function called print_array_as_html($array) .... then observe that it is a function. That's the idea of having functions/methods in a language , extend the functionality to get what you need.