The Red Matrix
 All Classes Namespaces Files Functions Variables Pages
language.php File Reference

translation support More...

Functions

 get_browser_language ()
 Get the browser's submitted preferred languages. More...
 
 get_best_language ()
 Returns the best language for which also a translation exists. More...
 
 push_lang ($language)
 
 pop_lang ()
 
 load_translation_table ($lang, $install=false)
 
 t ($s, $ctx= '')
 translate string if translation exists. More...
 
 tt ($singular, $plural, $count, $ctx= '')
 
 string_plural_select_default ($n)
 
 detect_language ($s)
 Takes a string and tries to identify the language. More...
 
 get_language_name ($s, $l=null)
 Returns the display name of a given language code. More...
 

Detailed Description

translation support

This file contains functions to work with translations and other language related tasks.

Function Documentation

detect_language (   $s)

Takes a string and tries to identify the language.

It uses the pear library Text_LanguageDetect and it can identify 52 human languages. It returns the identified languges and a confidence score for each.

Strings need to have a min length config['system']['language_detect_min_length'] and you can influence the confidence that must be met before a result will get returned through config['system']['language_detect_min_confidence'].

See Also
http://pear.php.net/package/Text_LanguageDetect
Parameters
sA string to examine
Returns
Language code in 2-letter ISO 639-1 (en, de, fr) format

Referenced by item_store(), and item_store_update().

get_best_language ( )

Returns the best language for which also a translation exists.

This function takes the results from get_browser_language() and compares it with the available translations and returns the best fitting language for which there exists a translation.

If there is no match fall back to config['system']['language']

Returns
Language code in 2-letter ISO 639-1 (en).

Referenced by create_account().

get_browser_language ( )

Get the browser's submitted preferred languages.

This functions parses the HTTP_ACCEPT_LANGUAGE header sent by the browser and extracts the preferred languages and their priority.

Get the language setting directly from system variables, bypassing get_config() as database may not yet be configured.

If possible, we use the value from the browser.

Returns
array with ordered list of preferred languages from browser

Referenced by get_best_language().

get_language_name (   $s,
  $l = null 
)

Returns the display name of a given language code.

By default we use the localized language name. You can switch the result to any language with the optional 2nd parameter $l.

$s and $l can be in any format that PHP's Locale understands. We will mostly use the 2-letter ISO 639-1 (en, de, fr) format.

If nothing could be looked up it returns $s.

Parameters
$sLanguage code to look up
$l(optional) In which language to return the name
Returns
string with the language name, or $s if unrecognized
load_translation_table (   $lang,
  $install = false 
)

Referenced by push_lang().

pop_lang ( )
push_lang (   $language)
string_plural_select_default (   $n)
t (   $s,
  $ctx = '' 
)

translate string if translation exists.

Parameters
$sstring that should get translated
$ctxoptional context to appear in po file
Returns
translated string if exists, otherwise return $s

Referenced by account_remove(), achievements_content(), acl_init(), admin_content(), admin_page_channels(), admin_page_dbsync(), admin_page_hubloc(), admin_page_logs(), admin_page_logs_post(), admin_page_plugins(), admin_page_profs(), admin_page_site(), admin_page_site_post(), admin_page_summary(), admin_page_themes(), admin_page_users(), admin_post(), advanced_profile(), alt_pager(), api_content(), api_post(), api_statuses_public_timeline(), app_render(), app_store(), app_update(), appman_content(), appman_post(), apps_content(), apw_form(), attach_by_hash(), attach_by_hash_nodata(), attach_count_files(), attach_init(), attach_list_files(), attach_mkdir(), attach_store(), bb2diaspora_itembody(), bbcode(), block_content(), blocks_content(), bookmark_add(), bookmarks_content(), bookmarks_init(), catblock(), categories_widget(), channel_content(), channel_init(), chat_content(), chat_init(), chatroom_create(), chatroom_destroy(), chatroom_enter(), chatsvc_content(), check_account_email(), check_account_invite(), check_config(), check_form_security_std_err_msg(), check_funcs(), check_htaccess(), check_htconfig(), check_keys(), check_php(), check_smarty3(), check_store(), cloud_init(), common_content(), common_friends_visitor_widget(), common_init(), connect_content(), connect_init(), connect_post(), connections_content(), connections_post(), connedit_content(), connedit_post(), construct_page(), contact_block(), contact_poll_interval(), conversation(), create_account(), create_identity(), day_translate(), delegate_content(), design_tools(), diaspora_like(), dir_safe_mode(), dir_sort_links(), dir_tagblock(), directory_content(), dirsearch_content(), display_content(), dob(), drop_item(), editblock_content(), editlayout_content(), editpost_content(), editwebpage_content(), event_store_item(), events_content(), events_post(), fbrowser_content(), fileas_widget(), filer_content(), filestorage_content(), filestorage_post(), findpeople_widget(), follow_init(), foofoo(), format_categories(), format_event_diaspora(), format_event_html(), format_filer(), format_like(), format_notification(), fsuggest_content(), fsuggest_post(), gender_selector(), gender_selector_min(), RedMatrix\RedDAV\RedBrowser\generateDirectoryIndex(), get_birthdays(), Item\get_comment_box(), get_events(), get_features(), get_mood_verbs(), get_perms(), get_plink(), get_poke_verbs(), Item\get_template_data(), group_add(), group_content(), group_post(), group_side(), hcard_init(), help_content(), home_content(), RedMatrix\RedDAV\RedBrowser\htmlActionsPanel(), identity_check_service_class(), impel_init(), import_author_rss(), import_author_unknown(), import_channel_photo(), import_content(), import_post(), import_xchan(), dba_driver\install(), invite_content(), invite_post(), item_check_service_class(), item_content(), item_photo_menu(), item_post(), item_post_type(), items_fetch(), lang_selector(), layout_select(), layouts_content(), like_content(), like_puller(), load_database(), localize_item(), lockview_content(), locs_content(), locs_post(), login(), lostpass_content(), lostpass_post(), magic_init(), mail_content(), mail_post(), manage_content(), manual_config(), marital_selector(), marital_selector_min(), match_content(), menu_content(), menu_post(), menu_render(), message_content(), mimetype_select(), mini_group_select(), mitem_content(), mitem_init(), mitem_post(), mood_content(), mood_init(), nav(), network_content(), network_init(), network_to_name(), new_channel_content(), new_channel_post(), new_contact(), notice(), notification(), notifications_content(), notifications_post(), notify_content(), obj_verbs(), oembed_bbcode2html(), oembed_iframe(), oexchange_content(), openid_content(), page_init(), pagelist_widget(), paginate(), pdl_selector(), pdledit_content(), pdledit_post(), photo_upload(), photos_album_widget(), photos_content(), photos_init(), photos_post(), ping_init(), poke_content(), poke_init(), poll_content(), populate_acl(), post_activity_item(), post_init(), probe_content(), profile_activity(), profile_content(), profile_init(), profile_load(), profile_photo_post(), profile_sidebar(), profiles_content(), profiles_init(), profiles_post(), profperm_content(), pubsites_content(), rbmark_content(), rbmark_post(), redbasic_form(), register_content(), register_post(), regmod_content(), relative_date(), removeaccount_content(), removeaccount_post(), removeme_content(), removeme_post(), rmagic_content(), rmagic_post(), role_selector(), rpost_content(), scale_external_images(), search(), search_content(), searchbox(), select_timezone(), send_message(), send_reg_approval_email(), send_verification_email(), service_limits_content(), settings_post(), setup_content(), sexpref_selector(), sexpref_selector_min(), siteinfo_content(), sources_content(), sources_post(), subthread_content(), suggest_content(), sync_locations(), tagblock(), tagger_content(), tagrm_content(), tagrm_post(), theme_attachments(), thing_content(), thing_init(), timezone_cmp(), translate_scope(), translate_system_apps(), update_birthdays(), update_channel_content(), update_display_content(), update_home_content(), update_network_content(), update_search_content(), upgrade_bool_message(), upgrade_link(), upgrade_message(), user_allow(), user_approve(), user_deny(), validate_channelname(), vcard_from_xchan(), verify_email_address(), viewconnections_content(), viewsrc_content(), vote_content(), wall_upload_post(), webpages_content(), what_next(), widget_affinity(), widget_appselect(), widget_archive(), widget_bookmarkedchats(), widget_chatroom_list(), widget_filer(), widget_follow(), widget_mailmenu(), widget_notes(), widget_photo(), widget_photo_rand(), widget_savedsearch(), widget_settings_menu(), widget_suggestedchats(), widget_suggestions(), widget_tagcloud(), writepages_widget(), xchan_content(), z_readdir(), and zfinger_init().