I tried to find an answer to this everywhere but no success. But it must be a common issue I guess ....

We have a english PHP web project with many PHP source code files
Now we want to translate the whole project inte 3 new languages (swedish/italian/spanish)

I'm looking for nice a source code editor with support for many languages.
I guess I want to "tag" some text in the source code as "plain text" so it's language can be changed (english/swedish/ ....)

An example might explain better

function MyEcho()  {
   echo "Soccer is booring";

I want to tag "Soccer is booring" so that I can maintain a dictionary that this tag should be translated to "Fotboll är tråkigt" in swedish

Diffcult to explain .... but I hope you understand
anyway this must be a very common wish

Thanks in advance!

Recommended Answers

All 4 Replies

e text in the source code as "plain text" so it's language can be changed (english/swedish/ ....)

An example might explain better

Hey, basically, a language convertor?

You can use Google's Translate API for this.


Hope this helps

Thanks for your answer.
But this was not really what I was thinking about.
I have PHP source code files with mixed PHP code and language specific text (like "Error in connect"). I want to use the same source code and publish for different langauges. There must be an editor out there supporting this ....??


Member Avatar for diafol

This is difficult to implement IMO. For example how would your parser be able to detect if a string was language specific as opposed to some generic text like 'sitename'.

I would seriously look at developing a robust i18n system and provide localization files or alternate strings.
There are many approaches you could use, such as GETTEXT and .mo/.po files; language files containing arrays of strings. DB held string tables.

While all these are usable, they can be fiendishly difficult to maintain. I usually use template systems, like RainTPL or more recently Twig, or even pseudo-templaters using include files. I've recently started using str_replace/preg functions on heredoc snippets in this format. These are individual include files for pages. It has the advantage of keeping all the translation strings in one place. This uses language format WELSH||ENGLISH

$title= '{{Ynghylch AlCemegol||About Alcemegol}}';
$description= '{{Darganfyddwch fwy am y gwaith tu ôl i AlCemegol, manylion cysylltu ac am ein termau, defnydd cwcis a phreifatrwydd||Find out about the work behind AlCemegol, contact details and about our terms, cookie use and privacy}}';

$content = <<<"CONTENT"
    <h3>{{Termau Gwasanaeth||Terms of Service}}</h3>
    <p>{{Mae'r wybodaeth ar y safle hwn yn cael ei derbyn fel ydyw. Tra fy mod i wedi cymryd camau i sicrhau cywirdeb y wybodaeth yma, 'sdim gwarant fod y wybodaeth yn gywir. O ganlyniad, rydych chi'n defnyddio'r safle hwn a derbyn y wybodaeth yma ar risg eich hun.||The information on this site should be taken as is. While I have taken steps to ensure that the information is correct, there can be no guarantee, therefore you use this site at your own risk.}}</p>

I'm not saying that this is the best approach, but I find it really straightforward. It could be expanded to multiple languages. If you're interested in this, I can provide more info. Everybody else - feel free to slap me down.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.