Skip to content

Commit

Permalink
Merge pull request #9 from JLouback/i18n-add
Browse files Browse the repository at this point in the history
I18n add
  • Loading branch information
JLouback committed Jul 14, 2014
2 parents 1aaa165 + b383329 commit 19c6b2f
Show file tree
Hide file tree
Showing 15 changed files with 486 additions and 3 deletions.
46 changes: 46 additions & 0 deletions INTERNATIONALIZATION_README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

How to add internationalization options
------------------------------------------------

The jQuery i18n plugin is used to provide internationalization.
see https://code.google.com/p/jquery-i18n-properties/ for more info.

To add a language option, create a ‘.properties’ file in the internationalization directory in the following format: Messages_[language code of choice].properties
Example: Messages_fr.properties for French.

Copy the content of the default .properties file (Messages.properties) into your new .properties file. The file will have a series of key-value pairs; leave the left side as is and add your translation on the right side.
Example:
(in Messages.properties) jsc_login_display_name = Display name (may be empty)
(in Messages_fr.properties) jsc_login_display_name = Nom (peut être vide)

Add a language element to the available_languages.xml with the name to be displayed and language code.
Example:
<language>
<display>French</display>
<code>fr</code>
</language>

Voila!

Behind the scenes
------------------------------------------------

jQUery i18n will automatically load the .properties file according to the language preference of your browser (if that file exists in the internationalization directory). If a .properties file for you preferred language doesn’t exist, it will default to Messages.properties which is in English.

The available_languages.xml is used to load the language selection drop down menu. If you added a language to the .xml which does not exist in the .properties file, it will default to English. Same goes for any mistakes in the <code> element. jQuery will look for a file Messages_[content of <code>].properties so make sure the name is correct.


Dependencies
------------------------------------------------

jquery.i18n.properties-1.0.9.js (see https://code.google.com/p/jquery-i18n-properties/)


Observed bugs
------------------------------------------------

It is recommended to consult the HTML language code (reference http://www.w3schools.com/tags/ref_language_codes.asp). Theoretically, you can invent your own code, and (provided the code in available_languages.xml corresponds to the name of the .properties file) the select language menu will work. However, the page will not load automatically with the browser language preference (as this uses the HTML language code.

In addition, different browsers may use different variations of code. For example: ‘en’ and ‘en_US’. To work around this, feel free to make multiple versions of your translation (example: Messages_en.properties and Messages_en_US.properties). Of course, you only need to add one to the available_languages.xml.

I think that’s it.
6 changes: 6 additions & 0 deletions JSCommManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ window.JSCommManager = {
Arbiter.publish("jsc/unavailable/config", null, {async:true});
return false;
}

/* load internationalization options */
if(JSCommSettings.i18n.translate) {
i18n.initI18n(JSCommSettings.i18n.show_menu);
}


this.currentURL = parseUri(window.location.toString());
if(this.currentURL.queryKey["dial"]) {
Expand Down
19 changes: 19 additions & 0 deletions available_languages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<list>
<language>
<display>English</display>
<code>en</code>
</language>
<language>
<display>Français</display>
<code>fr</code>
</language>
<language>
<display>Español</display>
<code>es</code>
</language>
<language>
<display>Português</display>
<code>pt</code>
</language>
</list>
6 changes: 6 additions & 0 deletions config-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ JSCommSettings = {
// the lack of a relay candidate is
// likely to be a sign that UDP is blocked
},

i18n : {
translate: true, // enables the call to i18n init function from JSCommManager.init()
show_menu: true, // show the language chooser menu
default_lang: 'en', // default language to use
},

extra_headers : [
// 'X-WS-Session-Extra: some_token=value'
Expand Down
1 change: 1 addition & 0 deletions event-demo.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="style-event-demo.css" type="text/css"/>
<script src="jquery.js" type="text/javascript"></script>
<script src="Arbiter.js" type="text/javascript"></script>
<script src="jquery.i18n.properties.js" type="text/javascript"></script>
<!--<script src="http://jssip.net/download/jssip-devel.js"></script>-->
<script src="JsSIP.js" type="text/javascript"></script>
<script src="init.js" type="text/javascript"></script>
Expand Down
223 changes: 223 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
(function ($) {

window.i18n = {
// load I18N bundles
initI18n : function(show_menu) {

if(JSCommSettings.i18n.default_lang) {
try {
i18n.loadBundles(JSCommSettings.i18n.default_lang);
} catch (error) {}
}
else {
try {
i18n.loadBundles(jQuery.i18n.browserLang());
} catch (error) {}
}


if(show_menu) {
$("#lang_selection").show();
$.ajax({
type:"GET",
url:"available_languages.xml",
dataType: "xml",
success: function(xml) {
$(xml).find("language").each(function() {
var display = $(this).find('display').text();
var value = $(this).find('code').text();
$('#lang_selection').append('<option value=' +value+ '>' +display+ '</option>');
});
}
});

// configure language combo box
jQuery('#lang_selection').change(function() {
var selection = $(this).val();
i18n.loadBundles(selection != 'lang_selection' ? selection : null);
});
}
else {
$("#lang_selection").hide();
}
},


loadBundles : function (lang) {
jQuery.i18n.properties({
name:'Messages',
path:'internationalization/',
mode:'both',
language:lang,
callback: function() {
i18n.internationalize();
}
});
},

internationalize : function () {
// Accessing values through the map
var msg1 = 'error_js';
var msg2 = 'error_webrtc';
var msg3 = 'error_no_config';
var msg4 = 'error_ua_init_failure';
var msg5 = 'error_reg_fail';
var msg6 = 'error_call_attempt_failed';
var msg7 = 'error_dynamic';
var msg8 = 'jsc_login_display_name';
var msg9 = 'jsc_login_sip_uri';
var msg10 = 'jsc_login_password';
var msg11 = 'jsc_login_button';
var msg12 = 'ws_link';
var msg13 = 'ws_state_connected';
var msg14 = 'ws_state_disconnected';
var msg15 = 'sip_reg';
var msg16 = 'sip_reg_up';
var msg17 = 'sip_reg_down';
var msg18 = 'sip_dest_address';
var msg19 = 'session_state_outgoing';
var msg20 = 'session_state_incoming';
var msg21 = 'session_state_accepted';
var msg22 = 'session_state_active';
var msg23 = 'button_session_cancel';
var msg24 = 'button_session_reject';
var msg25 = 'button_session_answer';
var msg26 = 'button_call_audio';
var msg27 = 'button_reg';
var msg28 = 'button_dereg';
var msg29 = 'button_call_audio_video';
var msg30 = 'button_session_answer_video';
var msg31 = 'button_session_answer_hold';
var msg32 = 'button_session_answer_hang_up';
var msg33 = 'button_video_control_self_view';
var msg34 = 'button_video_control_self_hide';
var msg35 = 'button_video_control_full_screen';

jQuery('#error #js')
.empty()
.append(jQuery.i18n.prop(msg1));

jQuery('#error #webrtc')
.empty()
.append(jQuery.i18n.prop(msg2));

jQuery('#error #no-config')
.empty()
.append(jQuery.i18n.prop(msg3));

jQuery('#error #ua-init-failure')
.empty()
.append(jQuery.i18n.prop(msg4));

jQuery('#error #reg-fail')
.empty()
.append(jQuery.i18n.prop(msg5));

jQuery('#error #call-attempt-failed')
.empty()
.append(jQuery.i18n.prop(msg6));

jQuery('#error #dynamic')
.empty()
.append(jQuery.i18n.prop(msg7));

jQuery('#jsc-login-display-name .jsc-login-label')
.empty()
.append(jQuery.i18n.prop(msg8));

jQuery('#jsc-login-sip-uri .jsc-login-label')
.empty()
.append(jQuery.i18n.prop(msg9));

jQuery('#jsc-login-password .jsc-login-label')
.empty()
.append(jQuery.i18n.prop(msg10));

jQuery('#jsc-login-button')
.val(jQuery.i18n.prop(msg11)).change();

jQuery('#ws #ws_link')
.empty()
.append(jQuery.i18n.prop(msg12));

jQuery('#ws #connected')
.empty()
.append(jQuery.i18n.prop(msg13));

jQuery('#ws #disconnected')
.empty()
.append(jQuery.i18n.prop(msg14));

jQuery('#reg')
.empty()
.append(jQuery.i18n.prop(msg15));

jQuery('#reg .state #up')
.empty()
.append(jQuery.i18n.prop(msg16));

jQuery('#reg .state #down')
.empty()
.append(jQuery.i18n.prop(msg17));

jQuery('#control #reg-button')
.val(jQuery.i18n.prop(msg27)).change();

jQuery('#control #de-reg-button')
.val(jQuery.i18n.prop(msg28)).change();



jQuery('#dial-controls #dest #dest_label')
.empty()
.append(jQuery.i18n.prop(msg18));

jQuery('#dial-controls #dialing-actions #call-audio')
.empty()
.append(jQuery.i18n.prop(msg26));

jQuery('#dial-controls #dialing-actions #call-video')
.empty()
.append(jQuery.i18n.prop(msg29));


jQuery('#session-controls #state .session-outgoing')
.val(jQuery.i18n.prop(msg19)).change();

jQuery('#session-controls #state .session-incoming')
.val(jQuery.i18n.prop(msg20)).change();

jQuery('#session-controls #state .session-accepted')
.val(jQuery.i18n.prop(msg20)).change();

jQuery('#session-controls #state .session-active')
.val(jQuery.i18n.prop(msg22)).change();

jQuery('#peer #session-actions #session-cancel')
.val(jQuery.i18n.prop(msg23)).change();

jQuery('#peer #session-actions #session-reject')
.val(jQuery.i18n.prop(msg24)).change();

jQuery('#peer #session-actions #session-answer')
.val(jQuery.i18n.prop(msg25)).change();

jQuery('#peer #session-actions #session-hold')
.val(jQuery.i18n.prop(msg31)).change();

jQuery('#peer #session-actions #session-hangup')
.val(jQuery.i18n.prop(msg32)).change();

jQuery('#video-session #video-controls #video-control-self-view')
.val(jQuery.i18n.prop(msg33)).change();

jQuery('#video-session #video-controls #video-control-self-hide')
.val(jQuery.i18n.prop(msg34)).change();

jQuery('#video-session #video-controls #video-control-fullscreen')
.val(jQuery.i18n.prop(msg35)).change();


}
};
})(jQuery);
35 changes: 35 additions & 0 deletions internationalization/Messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error_js = ERROR: This service requires JavaScript. Please enable JavaScript in your web browser settings.
error_webrtc = ERROR: This service requires WebRTC. Please try <a href="http://www.mozilla.org">Mozilla Firefox</a> or <a href="http://www.google.com/chrome">Google Chrome</a>, using the latest version is strongly recommended.
error_no_config = ERROR: JsCommunicator configuration not found.
error_ua_init_failure = ERROR: Failed to initialize user agent.
error_reg_fail = ERROR: SIP Registration failure.
error_call_attempt_failed = ERROR: Failed to start call, check that microphone/webcam are connected, check browser security settings, peer may not support compatible codecs.
error_dynamic = " "
jsc_login_display_name = Display name (may be empty)
jsc_login_sip_uri = SIP address
jsc_login_password = Password
jsc_login_button = Login
ws_link = WebSocket link:
ws_state_connected = Connected
ws_state_disconnected = Disconnected
sip_reg = SIP registration:
sip_reg_up = Registered
sip_reg_down = Not Registered
sip_dest_address = Destination
session_state_outgoing = Dialing ...
session_state_incoming = Incoming call
session_state_accepted = Answering, connectivity checks in progress ...
session_state_active = Call connected
button_session_cancel = Cancel
button_session_reject = Reject
button_session_answer = Answer
button_call_audio = Call (audio only)
button_reg = Register
button_dereg = De-Register
button_call_audio_video = Call (audio and video)
button_session_answer_video = Answer (with video)
button_session_answer_hold = Hold
button_session_answer_hang_up = Hang-up
button_video_control_self_view = Self view
button_video_control_self_hide = Self hide
button_video_control_full_screen = Full screen
35 changes: 35 additions & 0 deletions internationalization/Messages_en.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error_js = ERROR: This service requires JavaScript. Please enable JavaScript in your web browser settings.
error_webrtc = ERROR: This service requires WebRTC. Please try <a href="http://www.mozilla.org">Mozilla Firefox</a> or <a href="http://www.google.com/chrome">Google Chrome</a>, using the latest version is strongly recommended.
error_no_config = ERROR: JsCommunicator configuration not found.
error_ua_init_failure = ERROR: Failed to initialize user agent.
error_reg_fail = ERROR: SIP Registration failure.
error_call_attempt_failed = ERROR: Failed to start call, check that microphone/webcam are connected, check browser security settings, peer may not support compatible codecs.
error_dynamic = " "
jsc_login_display_name = Display name (may be empty)
jsc_login_sip_uri = SIP address
jsc_login_password = Password
jsc_login_button = Login
ws_link = WebSocket link:
ws_state_connected = Connected
ws_state_disconnected = Disconnected
sip_reg = SIP registration:
sip_reg_up = Registered
sip_reg_down = Not Registered
sip_dest_address = Destination
session_state_outgoing = Dialing ...
session_state_incoming = Incoming call
session_state_accepted = Answering, connectivity checks in progress ...
session_state_active = Call connected
button_session_cancel = Cancel
button_session_reject = Reject
button_session_answer = Answer
button_call_audio = Call (audio only)
button_reg = Register
button_dereg = De-Register
button_call_audio_video = Call (audio and video)
button_session_answer_video = Answer (with video)
button_session_answer_hold = Hold
button_session_answer_hang_up = Hang-up
button_video_control_self_view = Self view
button_video_control_self_hide = Self hide
button_video_control_full_screen = Full screen
Loading

0 comments on commit 19c6b2f

Please sign in to comment.