hi
i have 30 pages with the same design, the text appears always in the same div so i have 30 different texts with the same div id. Is it possible to include all the text in an external php file not database and call them to appear one by one in their page.

Thanks

Member Avatar for diafol

Yes sure:

How is your external file formatted? Do you have key:value lines?
How are you going to know which text relates to which page?

Member Avatar for diafol

This is one of the standard methoids, popular with forum-type sites, where the majority of the site is user supplied text stored in a DB, with hundreds to thousands of simple array translation items. It's a very useful method if your site is of this type.

Another method, which is reasonably similar is the GETTEXT method, using PO/POT files, where you create a translation PO files (check out PoEdit for a decent editor).

Again, you can use the Python-based Pootle for online translation - but this can be a bit fiddly to set up your own. There are also web-based services that enable you to create the array or PO files. 'Launchpad' and 'Transifex' and 'Gengo' are alternatives.

Anyway, one disadvantage of all of these is the inconvenience of updating your language files. As they tend to be separate files / pages, it's a bit of a nuisance.

If your site is text-heavy, you'll be lookign at paragraphs or extended prose, which can exacerbate the inconvenience of using array files. A common fix for this would be to provide separate include files for each language, e.g. about_en.php and about_it.php. The file is included something like this:

include("includes/about_" . $lang . ".php");

Again this is quite inconvenient, having to deal with multiple files for simple updates.

Another approach, one that I've been investigating and developing lately is the 'all-in-one' solution:

One include file:

<p>{{Hi, how are you?||Salve, come stai?}}</p>
(etc)

I then run the whole file through a translate function, which basically strips the language(s) you don't want. This has the advantage of easy editing/updating BUT, depending one the size of the file, has the disadvantage of taking longer to load, as it uses the preg_replace function, which is a little slow if it has to make many replacements.

There are other methods, but you need to think about how your site is now and also, how it may develop in the future. For example, do you envisage adding additional languages? If so, will you be responsible for developing them or will you farm out the localizations to professional translators or volunteers? If you plan on farming it out, then the Pootle site, PO file or array file option will be the most useful.

//EDIT

I should add that I once used Spaw2 (a wysiwyg editor from Solmetra - I think they've stopped supporting it now, but worth a look maybe) to create a CMS-type system. The advantage of that was that it stored 'content', like articles in tabs in the editor, so you could tab through your languages. Again, not so useful for small sentences of a few words, but VERY good for extended prose. You could set it up to store the data in a DB or even as a set of text files. Even non tabbed editors can be used, e.g. run two instances of CKEditor or similar side by side, containing different localizations.

Member Avatar for diafol

BTW - just remembered. Ensure that your urls from different langs are different. SEO is impt. I usually do something like this:

www.example.com/en/home/    and    www.example.com/cy/hafan/

I use .htaccess to rewrite from

www.example.com?lang=en&page=index    and    www.example.com?lang=cy&page=index 
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.