Plugin / SrbTransLatin
Predrag SupurovićDescription
Description
SrbTransLatin handles using Serbian or Russian language Cyrillic and Latin script. For Cyrillic content, visitor may choose to view it using Cyrillic or Latin.
Contents of the site should be written using Cyrillic script. Then, this plugin will allow users to choose to read contents in Cyrillic or Latin script.
If some contents is entered in Latin script, it would stay in Latin even if user chooses to use Cyrillic. Transliteration occurs only from Cyrillic to Latin script.
Site owner may set default for script to show Cyrillic or Latin.
Script also may be selected manually, by adding ?script=cir or ?script=lat to document url. If parameter is not specified default script is used.
Site owner may use widget to allow visitors to choose among Cyrillic and Latin script. He may choose if script options are shown as html links or items of combo box. By default, html link are dipslayed. He also may set if widget would show title or not.
When user selects script, his choice stays permanent while he is on site. All internal links within site are altered to contain information about selected script. This means, when link is copied and pasted to some other site, it would contain information which script to use for displaying contents.
Initially, when new article is posted using Cyrillic script in title, permalink is created with conversion to Latin script. Site owner may turn it of.
Transliteration works for all feeds too (atom, rdf, rss, rss2).
Searching site using both scripts
Site search is possible in both Cyrilic and Latin script.
When user searches site, regardless what script is used for search keyword, search would be attempted in both Latin and Cyrillic form.
Transliteration of some letters from Serbian Latin to Cyrillic is not possible to be unique, so it may happen that some Latin searches are not properly transliterated, but that is something that cannot be fixed due to very nature of the Latin and Cyrilic scripts.
Disabling transliteration for part of page contents
When transliteration occurs, everything in the HTML document is transliterated from Cyrillic to Latin script except if contents is placed among [lang id=”skip”] and [/lang] tags. This leaves user to mark part of the text he does not want to be transliterated at all, meaning, some parts of Cyrillic text may stay Cyrillic even if user chooses to view site in Latin script.
Changing image depending on selected script
If you want to add image on page which contains Cyrillic text and you want it to be replaced with image that contains Latin script then add -cir- as suffix in image name. On transliteration, Image name will be changed to have -lat- as suffix.
Example: filename-cir-.jpg will be replaced with filename-lat-.jpg
You have to provide Latin version image at same path as Cyrillic image is placed, of course.
You may use other delimiter besides “-“. You have to set delimiter in plugin settings. Delimiter may be more than one character long.
Script mark may be placed anywhere in path, not just file name.
If you want to test there are two example files available in img directory of a plugin.
Using script selector on custom places
If you need to put script selector in site template outside widgets areas then you can use function stl_show_selector() provided with plugin. Function accepts four parameters (all optional):
stl_show_selector (selector_type, oneline_separator, cyrillic_caption, latin_caption, inactive_script_only, show_only_on_wpml_languages)
selector_type chooses which type of selector to display:
-
links – list of choices in form of widget items
-
list – list of choices in form of dropdown selection
-
oneline – list of choices as one line separated by oneline_separator
Default value is ‘oneline’
oneline_separator is a string that should be inservted between script selection items. Default value is ‘/’.
cirillic_caption is a string that should be used as caption for item of cyrillic sleection. Default is ‘ћирилица’
latin_caption is a string that should be used as caption for item of latin sleection. Default is ‘латиница’
inactive_script_only if checked dosplays only option to select inactive script, currently active script wil not be an option
show_only_on_wpml_languages contains list of WPML languages comma separated for which script selection swhould be visible
To use this function just call it from place where you need code to be inserted, like:
<?php stl_show_selector('oneline', '/', 'ћирилица', 'латиница') ?>
Selector templates are stored in plugins ‘template’ directory. IF you want to customiye, you may copy template to your template directory and customize there.
Using script info in custom code
You may use some info about script state for customizing templates. Here are available functions:
stl_get_current_script() – returns id of currently displayed script. It returns id as set in plugin options.
stl_is_current_cyrillic() – returns true if currently displayed script is Cyrillic.
stl_is_current_latin() – returns true if currently displayed script is Latin.
stl_get_cyrillic_id() – returns id of Cyrillic script as set in plugin settings.
stl_get_latin_id() – returns id of Lating script as set in plugin settings.
stl_get_script_identificator() – returns identificator used in URL to select script as set in plugin settings.
Using script info as shortodes
Shortcodes available:
[stl_get_current_script] – inserts currently displayed script.
[stl_get_script_identificator] – inserts identificator of current script.
[stl_get_cyrillic_id] – inserts id of Cyrillic script
[stl_get_latin_id] – inserts id of Latin script
[stl_is_cyrillic]content[/stl_is_cyrillic] – enclosed content will be displayed only if current script is Cyrillic
[stl_is_latin]content[/stl_is_latin] – enclosed content will be displayed only if current script is Latin
You can use these to alter behavior or looks of contents depending on durrent language inplaces where you cannot insert PHP code to call plugin functions.
** Using transliteration for custom purposes
If you need to transliterate other content by your own code (probably your plugin), you may use function stl_transliterate(). It accepts string that has to be transliterated and otuputs transliterated text. This may be used to transliterate mail before sent or text file generated or for some other purpose.
The function has two parameters:
The first parameter is a string that should be transliterated.
The second paramter is optional. It instructs if output has to be in specific script. If omited, output will be in current script selected by site visitor.
But, if you ned to output specific script you may set it by using script identificator. You may use functions stl_get_cyrillic_id() and stl_get_latin_id() to get identificators as set in plugin configuration (idnetificators are configurable).
Examples:
echo stl_transliterate($content);
echo stl_transliterate($content, stl_get_cyrillic_id());
echo stl_transliterate($content, stl_get_latin_id());
Using cookies
Site admin may turn on using cookies to save user’s script selection. If turned on, each time user opens page curent script selection is saved in cookie.
When user comes back to site using url that does not contain script identificator, site would use cookie and show content accordingly. If user comes to site using url that do contain script identificator, cookie would not be used – url has priority over cookie.
If cookies are used, script indentificator would not be added to urls.
Configuration file
There is config_example.php in SrbTransLatin directory. User may copy that to config.php and edit new file to set some additional options. This is supposed to use some rarely needed and very specific settings not needed by ordinaru users.
Sanitizing file names on upload
When files are uploaded to WordPress site, it is not good to let them have Cyrillic characters in file names. SrbTransLatin has optin to clean such characters and replace them with appropriate latin characters.
Not sanitized file names and URL-s within page
It happens that file sanitization on upload is not turned on, and actual uploaded files do have Cyrillic characters in names. By default such files will be accessible while site is viewed in Cyrillic but when Latin is chosen, Cyrillic characters will be removed.
If you have this issue there is option in Settings to skip transliteration of file names and URL-s. Turn it on and file names and URL-s will stay intact.
If you have xDebug and you turn on skipping transliteration of files and URL-s it may happen that you get blank page or error message saying something like: “PHP Fatal error: Maximum function nesting level of ‘100’ reached, aborting!”. That is because of limitation of 100 nesting levels in xDebug. To overcome it, use config.php in plugin directory to set $stl_config[‘xdebug_max_nesting_level’] to greater number. Plugin will set xDebug nesting levels accordingly.
Fix url collisions with other plugins
There are some plugins that also use default identificator ‘lang’, which SrbTransLatin uses to pass selected script information through url. To fix this there is an option to set this identificator. If you have problems with other plugins just change this to ‘script’ or ‘lng’, or something else as you like.
Pay attention that if you change this option, all previous urls containing script selection will become invalid. It is best to set this before site is heavily indexed or externally linked.
Fix priority collisions with other plugins
SrbTransLatin as a rule should be the last plugin executed, so it can process page content after all content is generated by other plugins. At least it should be the last of plugins that generate content.
By default, SrbTranslatin uses priority 99 to make good chance to be at the end of executing plugin list. If for some reason it does not work well, user can change priority.
User should edit config.php and and check line:
$stl_config[‘priority’] = 9999;
User may change number 9999 to any other. Greater number is lower priority, meaning exexuting after plugins with lower number.
WPML compatibility
It is quote often that users of SrbTranslatin als use WPML and they meet with conflict as both plugins use the same language identificator ‘lang’. SrbTransLatin has an option for user to set different language identificator to resolve conflict. It is recommend to use ‘script’ as identificator.
Moreover, on installation, SrbTranslatin will check if WPML is installed and it will change it’s language identificator. Also, when conflict is possible, warning will be presented to user while in SrbTransLatin settings.
When setting widget, or using user have an option to set language identificators used by WPML which for widget will be invisible.
Acknowledgements
This plugin is developed inspired by two plugins WP Translit by Aleksandar Urošević and srlatin by Kimmo Suominen. I actually merged functionality of these two and expanded it with a lot of new functionality I needed for my site, and later with new functionality asked by plugin users.
Vanja Đurić suggested skipping transliteration of file names and URL-s and provided example code to do that, which I included with minor alterations. Vanja also suggested solution for xDebug max_nesting_level issue.
Ratings
Rating breakdown
Details Information
Version
First Released
Total Downloads
Wordpress Version
Tested up to:
Require PHP Version:
Tags
Contributors
Languages
The plugin hasn't been transalated in any language other than English.
DIRECTORY DISCLAIMER
The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.
The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.
Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.
While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.
wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.