views:

230

answers:

2

Hi,

I'm building a small site, that needs to support 2 languages for the same page.
Each language has different buttons on the page, the buttons are basically some images with text inside. The positioning of the buttons is done using a CSS file, one for every language. Question is how do I implement the changing of button for every image. I could put a php if statement, and use some other src if lang == English or something else if lang == Russian, Or could implement this with the css file (I could do this with a div and set it's background in the CSS)?
What would you recommend?

Cheers.

A: 

I would recommend using CSS by setting the background and size of the button.

use < button> tag, its better because you can use css like "button{}" without having to put a class on it. Just a remind that < button> has a type like the input and it is "submit" as default if I remember correctly.

Btw, always try to depend on CSS instead of PHP, because on a next manutenance you will be glad that you did it.

or, if you going to use PHP, try using a function instead of hardcoding, even if it is just for one button, we never know if we will use it later.

hope it helped,
Joe

Jonathan
Doesn't answer the question at all.
Tatu Ulmanen
lol? (I could do this with a div and set it's background in the CSS). He knows what to do, he is asking the best way to do it, with PHP or CSS and I gave him what I think is the best answer.
Jonathan
+3  A: 

You could create three CSS files:

  • One for english buttons
  • One for russian buttons
  • One for the rest

This would basically work this way: You create your buttons with a fallback name, for example

<button id="button_ok">OK</button>

and define different background images in your english/russian CSS files:

(english.css)

#button_ok {
  background-image: url(images/buttons/eng/ok.gif);
}

and (russian.css)

#button_ok {
  background-image: url(images/buttons/rus/ok.gif);
}

All other elements that do not change when the language is chosen come in the third file:

p {
  font-size: 1em; /* whatever*/
}

The last step is to choose at the top of every page which file you want to load:

if ($_GET['lang'] == 'eng')
    $cssFile = 'english.css';
elseif ($_GET['lang'] == 'rus')
    $cssFile = 'russian.css';

and include the special and the general css file in your head:

<link rel="stylesheet" type="text/css" href="general.css" />
<link rel="stylesheet" type="text/css" href="<?php echo $cssFile; ?>" />
Cassy
I don't want to use a <button> tag, I just need an image..., so what do i do?
Haim Bender
if you just want to show the image without letting the user click on it, you can simply use a div element. So instead of `<button ...`, you simply use `<div ...`. You have to define width and height in the css classes then, but otherwise it works as described above
Cassy
Yeah thats the solution I used in the end, thanks. But I think it's kind of wrong because it makes you have to set the width and the height (smells fishy to me)
Haim Bender
From a strict point of view, it is the only right solution to set width and height (which is a style thing) in a css ;-)
Cassy