SimplePortal

Support => International Support => Topic started by: andy on February 07, 2011, 09:54:38 AM

Title: Translating block titles, custom block contents and custom SP pages
Post by: andy on February 07, 2011, 09:54:38 AM
I've been unable to find anything about translating the names of blocks (and html contents) or custom pages created in simple portal, and their titles - can you tell me where I can translate them?

Another one isn't really SP but related ... translating the custom menu items.


New to SMF and SP.
Andy
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on February 07, 2011, 10:37:44 AM
I am not sure I understand your question.  I will give some information.  If this does not answer your question, please ask some more.  Please be specific.
 
* You can install different language packs for SMF, and for SimplePortal. SimplePortal language packs are available at http://simpleportal.net/index.php?action=downloads;area=cat2;d64a17a12a=b415fb8cf24f5bbc52bc5ebd9ca81255 (http://simpleportal.net/index.php?action=downloads;area=cat2;d64a17a12a=b415fb8cf24f5bbc52bc5ebd9ca81255)
 
* If you wish to create a new language pack for your language, please ask here. SimplePortal.net has a tool to make this a little easier than editing the files directly.
 
* The files are all found in Themes/default/Languages/SPortal*.*.php
 
I hope this helps.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: andy on February 07, 2011, 11:43:36 AM
No... I already have the JP language pack for SMF and SP.

I have a site with 2 languages; English and Japanese. I'm moving from a Joomla based site to SMF with a portal but need all SP content - new block titles I make, block HTML content, custom pages, menu tabs etc, to be displayed in both languages when they are switched. At the moment these are only in English.
Right now it is a halfway house with Joomla providing the information pages with SMF in a wrapper. SSI hasn't worked well in Joomla blocks and there is no sync in the languages so I want to use an SMF portal.
http://outdoorclubjapan.com/ (http://outdoorclubjapan.com/)

I've been testing SMF with Simple Portal here (the one I want to translate):
http://paddington-school.com/smf/ (http://paddington-school.com/smf/)

http://paddington-school.com/smf/index.php?language=japanese-utf8 (http://paddington-school.com/smf/index.php?language=japanese-utf8)

The layout is not final in anyway but you can see that even when the browser detects Japanese and displays the site, all the block titles, contents, pages added in SP that I made, are still in English. I don't know where to access the language strings for these - if there are any. Or where to place equivalent Japanese utf-8 files - something like that standard files like SMF agreement.
Examples:
Left top block: 'Events and Discussion ' ... how to translate title to Japanese.
Information menu tab: Introduction, Event grade and safety.


Andy

Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on February 07, 2011, 02:14:20 PM
Now I think I understand your question.
You wish to have the block titles change depending on the language selected by the user.
 
SimplePortal does not provide a way to do that.
 
For blocks where you want to provide translations of HTML content, I will suggest that you can do it in the way that SMF and SimplePortal provide "strings" in many different languages.
 
* Instead of an HTML block for Welcome to OCJ, use a php block.
* Instead of the first 3 paragraphs, you would use $txt['OCJ-intro'], instead of the list, you can use $txt['OCJ-list'], instead of the Please Click Here for Japanese text, you can use $txt['OCJ-switchlanguages'] .... and so on.
* Pick a file to keep them in. Then keep them at the bottom of the appropriate-language versions of that file.
* In your php block, you would be echoing a little always-the-same HTML (for the same logo each time, for example), setting up things like lists, and then stringing together your translated strings. Depending on which language is loaded, you will have that version of your strings loaded.
 
For the block titles, my best advice to you for now is to put both titles, where possible, or leave the titles off where possible.
 
It would take a customization of Simpleportal code to allow using $txt strings in the block titles. Which would first take figuring out a sensible syntax for doing that.
 
This would make a good feature request, I think.
Your website is a good example of someone trying to build a multi-lingual portal page.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: andy on February 08, 2011, 05:09:46 AM
Doesn't sound too bad... I will have a go. And you are right the block titles can be done in both languages for most of them - its not a big deal.

One of the big things still outstanding are the pages and menus. Can they be switched if the language is changed?
I don't know what to name the file or where to put it, say for example:
http://paddington-school.com/smf/index.php?page=page3950 (http://paddington-school.com/smf/index.php?page=page3950)
This is one of the custom pages made via SP.

Thanks.
Andy

Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on February 08, 2011, 10:52:49 AM
The menu buttons are defined in Subs.php, in setupMenuContext.
 
You can see how menu buttons are added to the menu buttons array.
You can add your own buttons there.
 
You can see that setupMenuContext has been written to use $txt strings.
You can do that too -- write your own $txt strings.
 
Ordinarily, I would recommend you look into mods that help you manage your menu buttons without requiring you to write code yourself:
http://custom.simplemachines.org/mods/index.php?action=search;basic_search=menu (http://custom.simplemachines.org/mods/index.php?action=search;basic_search=menu)
http://custom.simplemachines.org/mods/index.php?action=search;basic_search=menu+button (http://custom.simplemachines.org/mods/index.php?action=search;basic_search=menu+button)
http://custom.simplemachines.org/mods/index.php?action=search;basic_search=top++menu (http://custom.simplemachines.org/mods/index.php?action=search;basic_search=top++menu)
 
But, as far as I can tell without actually looking at the code, these all require string literals for button titless and can't use $txt indexes.
 
That would be a nice feature request for one of these mods.
I bet there will be other, similar, mods coming out once SMF 2.0 is released.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: andy on February 08, 2011, 11:17:08 AM
Yes Im using a mod for the menus ...
Mod=6 Custom buttons / tabs with Sub Menus
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on February 08, 2011, 01:40:35 PM
You could consider talking to JohnCcCcCc about the possibility of using $txt indexes. Perhaps some funny {{ syntax to tell the code to use a text string instead of the string literal.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: andy on September 12, 2011, 01:42:42 PM
Back ... switched over to Simple Portal but as Im not a php programmer and things are not going as planned.

Could you give some examples of including different language text/html in a block?
Can I not just echo the whole html? Either in English or Japanese.

I looked online and couldnt find examples using $text variable calling a php file.

Only thing I found easy to have a go at was
<?php include("ocj-intro.php"); ?>
But it didnt produce anything.

If possible I would like to output the English html block from a file. I guess it has to go in;
/public_html/Themes/default/languages

Would this be ok for a file containing html to output?
ocj-intro.php

Also in there a Japanese version - would that be?
ocj-intro.japanese-utf8.php


Sorry, Im not familiar at all with php. Civil Engineer with a Masters in I.T. from 1989  :P
And I havent worked in computing or IT. Forgotten C, Assembler, Lisp ... maybe Pascal Ok


Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on September 12, 2011, 02:19:30 PM
$txt is just an array that SMF uses to store some text strings.
All the $txt strings are stored in files, and the files can be translated into different languages.

You can see $txt use throughout SMF and SimplePortal -- have a search in PortalBlocks.php, for example.

You can see where SimplePortal's language strings are stored -- in Themes/default/languages/SPortal.english.php, or example, contains most of SimplePortal's strings.

So, if you are creating custom block content, you could do it using a php block.
That content would contain a lot of lines like:
echo $txt['mysite_specialInfo_1'];

That would make the content translatable.

You would also have to load the correct language file. So if it was called "ocj-intro", you would
loadLanguage('ocj-intro', sp_languageSelect('ocj-intro') right at the top of your custom php block.

Then you would have to have ocj-intro.english-utf8.php, ocj-intro.japanese-utf8.php, etc.
Each of these language files would be laid out like the language files you can already find in your language directory.

Is this about as clear as mud?


;
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: andy on September 12, 2011, 04:06:29 PM
Hehe, yes clear as mud... I will have a go this week.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on September 13, 2011, 01:32:10 PM
Hehe, yes clear as mud...
I'm sorry to hear that. This means it will be a bit of a challenge to you.  I will ask our customizers if they are interested in this little challenge.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on September 13, 2011, 01:39:27 PM
another option, which would require less getting-into-files, would be to create different blocks for different languages. Then, they can be done in BBC or HTML or whatever you like. Completely separately.
 
Only, don't display these blocks on any pages of the forum.
Use a simple form of blocks-in-blocks to choose the correct block depending on the language.
http://simpleportal.net/index.php?topic=5332.0 (http://simpleportal.net/index.php?topic=5332.0)
 
Code: [Select]
$block = current(getBlockInfo(false, 49, false, false));  // Load block info
$block['style'] = sportal_parse_style('explode', $block['style'], true);  //Parse block style parameters.
template_block($block); // Output the block.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: steiger on January 17, 2013, 06:23:17 AM
Hi everyone!

I am also currently implementing a dual-language website and have the same problem that block titles can not be translated.
I have read this thread but do not understand how block-in-block would help in this case.

There is no way to enter multiple titles (one for each language) or no way to select a block for a specific language (in this case block-in-block could help).

Maybe the second alternative is easier to implement in SP than the first one?

Any ideas?
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: steiger on January 17, 2013, 07:37:17 AM
BTW, I have now implemented a quick hack for my PHP blocks to set the block title from within the block.
As I already use jquery for other parts of my site I decided to change the block title on the fly.

In this case '###whoisonline###' is entered as the block title:
Code: [Select]
global $txt;
echo '<script>
h3 = $("h3:contains(\'###whoisonline###\')");
h3.html(h3.html().replace(\'###whoisonline###\', \''.htmlentities($txt['who_title'], ENT_QUOTES).'?\'));
</script>';

it's not beautiful but it does its job :D


My problem is that this only works for my own PHP blocks but not for the SP supplied ones except that I could move the jquery code from the block to the SMF page template.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on January 25, 2013, 11:02:02 AM
Yes.  Changing this for the SP-supplied blocks would require changes to the code.
If you look through the code (the discussion in blocks-in-blocks gives clues on where to begin), you will see where the block titles are used.  Before that point, where the block titel is displayed, you woulud have to have something happeneing to do the translation.  So, perhaps during block formatting you do the translation, storing the result in (something), then you would have to use that (something) during display.

conceptually, the idea is easy. The details of actually implementing it is where you will find your little hassles.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: steiger on January 26, 2013, 10:07:58 AM
Quote
conceptually, the idea is easy. The details of actually implementing it is where you will find your little hassles.

I know but it depends if the SP team is already thinking about doing it or if I will try to mod something.
It appears that there is not much activity in this forum lately, so I don't know how active the SP community really is.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on January 27, 2013, 01:05:59 PM
I do believe that if you came up with a mod for that, it would be well-received.

The truth is that now is the time for the Simple Portal to find and recruit new developers.
I believe that the best way to develop for Simple Portal right now is by creating mods for Simple Portal.

Lots of people want this; they will say thank you to you!
If it is GREAT code, "everyone" will lobby to get it into some future version of Simple Portal.

Go for it.
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: steiger on January 27, 2013, 01:09:31 PM
Let's see.
I just went live with my migrated website and after >250h in the last weeks I need some distance to this. ;D
Title: Re: Translating block titles, custom block contents and custom SP pages
Post by: AngelinaBelle on January 31, 2013, 08:24:58 AM
Congratulations on going live with your website.
There is no pressure on you to create a new mod for Simple Portal.

If you decide to work on it, you will get as much help as the denizens around here can provide.
And a resounding pat on the back for any useful stuff you produce!

Enjoy your website and welcome to Simple Portal
SimplePortal 2.3.8 © 2008-2024, SimplePortal