Editing story item type and theme display

Hi There,

I have a couple of things I’d like to change in the story item type and the way it is styled by Curatescape.

Firstly, what would I change if I wanted to add an additional field to stories (I’m assuming this would involve editing php) - e.g. another story field identical to the English story field except that it draws on a different metadata attribute added to the Curatescape Story item type. So Story attribute > Story displayed in CSS, Story (Welsh) > Another identically styled story block below the first styled in CSS. Is there any way I can make those expandable and collapsible?

Secondly, what would I need to change to make the labelled fields bilingual. I.e. leave what is in the tags the same, but change the text labelling the field as ‘Tags:’ to read ‘Tags | Tagiau:’

We’re exploring different experimental options for bilingualism still and I’m learning a lot, but any help would be great.

All the best,
James

Hi @james-smith,

This could be a somewhat complicated issue, depending on your prior coding experience. But the first step is relatively straightforward – though not without some challenges – so I would recommend starting by translating static labels.

1. Translating labels

The translation process is outlined in the Omeka documentation. You will need to generate translations for any static labels that are not already covered. Anywhere you see a string in the code like __('Tags') (with two underscores preceding quoted text in parenthesis), that string can be automatically updated to the Welsh equivalent if it is already in the .po/.mo translation files. A user should automatically see Tagiau instead of Tags if they have Welsh set as their language of choice (either in the browser or via a language-switching plugin).

In the case of strings like “Tags,” “Items,” etc, those should already be translated to Welsh and work without further change (since, I think, Omeka ships with a basic Welsh translation), but you’ll need to add ones that are unique to the Curatescape theme (e.g. “View a random story,” “Tour,” etc.).

NOTE: Before getting into more complicated changes, I should point out that manually editing the theme will impact your ability to get updates going forward. You will essentially be taking on the task of maintaining your own theme since any future updates will overwrite your changes.

That said, here are some pointers:

2. Adding a new field

You can edit item types at /admin/item-types. There you could add a field like Story (Welsh) to the Curatescape Story item type.

3. Displaying a new field

The story text is generated using a function called mh_the_text(), which you can see in the custom.php file at line 915:

(That function currently uses the Dublin Core Description as a fallback if there is no value for the Story field, but that is a legacy functionality that will be removed so you can ignore it.)

To show both English and Welsh versions at once, you could update that function to something like this (assuming your new field is called “Story (Welsh)”):

function mh_the_text($item='item',$options=array()){
	
    $welsh_text = element_exists('Item Type Metadata','Story (Welsh)') ? '<div class="welsh">'.metadata($item,array('Item Type Metadata', 'Story (Welsh)'),$options).'</div>' : null;
    $primary_text = element_exists('Item Type Metadata','Story') ? '<div class="english">'.metadata($item,array('Item Type Metadata', 'Story'),$options).'</div>' : null;
	
	return $primary_text ? replace_br($primary_text.$welsh_text) : null;
}

Your implementation may vary depending on how your language-switching plugin works and what you have in mind for the user experience.

You would also need to do something similar in several other functions, including for the title, subtitle, lede, etc. All those functions can be found in the custom.php file and are implemented throughout the theme, including in items/show-template-default.php, among many others.

4. Styling the new field

You’ll need to use CSS to modify how (and possibly when) the new fields appear to the user (i.e. when they have a particular language set, you may want to hide/show the English/Welsh). The details will depend again on your preferences as well as how the language-switching plugin works. To add something like a toggle, you’d probably want to use JavaScript.

5. Other

You will likely find some areas that cannot be translated using the methods above. These would include any strings that are generated using JavaScript (e.g. the slide out menu, the map marker popups, etc). Those would need to be handled on a case by case basis and would likely involve using a combination of PHP, JavaScript, HTML, and CSS.

Thanks again Erin. We’re just trying to find a formula that works for us and exploring our options. Those options are very helpful.

I have one more question for you Erin. The solutions we have in place for bilingual content are almost exactly what we want.

I’m assuming that I’d want to do something similar in custom.php to the php you’ve included above for the lede separated by " | " with Lede followed by the pipe followed by Lede (Welsh), but I’d be grateful for some guidance. I especially don’t 100% know how to return the text in the right format.

All the best,
James

You’ll want to locate the mh_the_lede() function (around line 952) in custom.php and edit it in a similar fashion.

I used ternary shorthand in the example above, but you can also write it out using the longer convention if that’s easier to read.

The updated lede function might look something like:

function mh_the_lede($item='item'){
	// does English lede field exist?
	if (element_exists('Item Type Metadata','Lede')){
		// does it have data?
		if(metadata($item,array('Item Type Metadata', 'Lede'))){
			$lede = '<div class="english">'.metadata($item,array('Item Type Metadata', 'Lede')).'</div">';
		}else{
			$lede = null;
		}
	}else{
		$lede = null;
	}
	// does Welsh lede field exist?
	if (element_exists('Item Type Metadata','Lede (Welsh)')){
		// does it have data?
		if(metadata($item,array('Item Type Metadata', 'Lede (Welsh)'))){
			$welsh_lede = '<div class="welsh">'.metadata($item,array('Item Type Metadata', 'Lede (Welsh)')).'</div">';
		}else{
			$welsh_lede = null;
		}
	}else{
		$welsh_lede = null;
	}
	// combine both ledes for output as HTML
	$output = $lede.$welsh_lede;
	
	// is there anything to output or did we just combine two nulls
	if($output !==null){
		return  '<div class="lede">'.strip_tags($output,'<a><em><i><u><b><strong><strike>').'</div>';
	}
}

Again, you’ll need to do stuff like this throughout the theme, wherever multilingual text is displayed. Each case will be different (and in multiple existing functions), so it might be a matter of trial and error until you find them all.

In addition to basic PHP, you may also want to look at the Omeka documentation – particularly for element_exists() and metadata() – if you’re not understanding how certain functions work.

Thanks Erin. It’s more that I’m just trying to learn how php works when my only experience is with basic javascript, so every example you give me is very educational. I really appreciate you taking the time to help me out.