Jump to content

Best way to let users translate selectbox values


LostKobrakai
 Share

Recommended Posts

Hi,
 
I'm just refactoring the FieldtypeEvent module into an address fieldtype. Now I wanted to use the mysql enum type for the title field, which should only consist of 0, 1 and 2 for "not provided", "sir" and "madam". By now I just use a INT field, because I didn't have to bother about mysql for a long time and wasn't really into it the time ago. So I would appreciate if someone could help me out with this.

Edit: After reading the mysql docs more closely it seems I imagined this to work a little different.

Secondly: What would be a favourable approach to internally translate those three numbers to labels the user can provide in the module settings. I would do this with three textfields, which dynamicly would change to languagetext, it they are available. By now I use a constant in the Address class, but I would also need these values to build the select field in the InputfieldAddress class.

class AddressGerman extends WireData {

	const title = array(
		0 => 'No title provided',
		1 => 'Sir',
		2 => 'Madam'
	);
…
Link to comment
Share on other sites

Note to myself: Stop reinvent the wheel. I ended up just using standart code translation. If someone wants to translate it, he / she should know how to do it, without these extra module settings. 

class AddressGerman extends WireData {

	protected $titleOutput;

…

	public function __construct(Page $page) {

 		$this->titleOutput = array(
			0 => $this->_('No title provided'),
			1 => $this->_('Sir'),
			2 => $this->_('Madam')
		);

…
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...