Some website strings are stored in database. These values can be added / updated by user from the OSClass Admin interface. Since these values are stored in database, by default, we cannot re-use the translation method as described in previous post.
OSClass page title and description
User can set these fields from the OSClass Administration interface: Settings > General Settings >
- Page title
- Page description
Unfortunately, no translations can be made here.
PHP looked up the above values for display, from database with osc_page_title() and osc_page_description().
PHP looked up the above values for display, from database with osc_page_title() and osc_page_description().
OSclass search bar pageholder text
Similarly, user can set the placeholder text at the main search bar of bender-theme from the OSClass administration interface.
Settings > Appearance > Theme settings > Search placeholder
Settings > Appearance > Theme settings > Search placeholder
Unfortunately, no translations can be made here.
PHP looked up the above values for display, from database with osc_get_preference(‘keyword_placeholder’, ‘bender')
PHP looked up the above values for display, from database with osc_get_preference(‘keyword_placeholder’, ‘bender')
The following is done to make offline translation easier (gettext() + po file translation):
Presentation
- Search for the above functions from both OSClass and bender-theme
- Put gettext() calls around them at each calling instance (if it is subsequently being used to output as HTML)
__( osc_XXX(), ‘DB_Values') - Define a new ‘text-domain’ to group this kind of strings. In this case, I name it ‘DB_Values’. I passed it as the second argument to the gettext() calls:
__( string-arg, ‘DB_Values’);
Translation Management
- Produce a new PO-Template for DB_Values
- Generate database objects with peewee
- Write script (Python) to extract values from corresponding databases tables using the generated objects.
- Put those extracted string values into a PHP file. It could be as simple as
_e(‘page title value’);
_e(‘page description value’);
_e(‘search placeholder value’); - Use makepot.php to create a POT file with a new domain (DB_Values) on the above produced php file.
- Perform translations as described in previous post.
- Modify Translation.php to load this DB_Values.mo files, similar to the way how ‘core’ and ‘messages’ are loaded.
- Installation
- Add DB_Values po + mo files to the language-pack.
- Update the language-pack with oc-admin
- Update the bender-theme with oc-admin
- Update Osclass
There are other fields that require similar conversions, such as:
- Geographical locations of For-Sale Item
- Settings > Locations
- Search for: osc_item_city(), osc_item_region(), osc_list_region_name()
- Geographical locations of User
- Search for: osc_user_city(), osc_user_region(), osc_user_country()
- Search for: osc_user_city(), osc_user_region(), osc_user_country()
- Custom Fields
- Settings > Listings > Custom Fields
- Search for: ‘$option’ or ‘$field’ variable and put gettext call ___() around where it will be presented in HTML. Places where it is likely to appear:
- HTML Form where user submits/modify an item.
- Page where the Item is displayed to website visitors.
- E.g. oc-includes/osclass/frm/Field.form.class.php
- HTML Form where user submits/modify an item.