Permalink
Browse files

dynamically load latest messages from github

app releases and i18n efforts are out of sync. This bridges this gap
by attempting to load from github instead
  • Loading branch information...
1 parent 5ca0936 commit d537baa7e73b522ffd6f8e165648f7862945ac2d @jrobson jrobson committed Sep 18, 2012
Showing with 26 additions and 24 deletions.
  1. +1 −0 assets/www/js/config.js
  2. +25 −24 assets/www/js/l10n.js
View
@@ -1,6 +1,7 @@
var WLMConfig = {
BLOCKING_POLICY: 'http://commons.wikimedia.org/wiki/Commons:Blocking_policy?uselang=$1',
COMMONS_API: 'https://commons.wikimedia.org/w/api.php',
+ GITHUB_MESSAGES: 'https://raw.github.com/wikimedia/WLMMobile/master/assets/www/',
MONUMENT_API: 'http://wlm.wikimedia.org/api/api.php',
MONUMENT_SEARCH_LIMIT: 50, // amount of monuments to request in a single query (see bug 39182 for more context)
SIGNUP_PAGE: 'https://commons.wikimedia.org/w/index.php?title=Special:UserLogin&type=signup&uselang=$1',
View
@@ -38,32 +38,33 @@ define(['jquery', 'propertiesFileReader'], function($, propertiesFileReader) {
//console.log('loading messages for ' + lang);
lang = normalizeLanguageCode(lang);
var url = /*ROOT_URL +*/ 'messages/messages-' + lang + '.properties';
- console.log('Loading messages: ' + url);
- $.ajax({
- url: url,
- //async: false, // fails on WinPhone7.1
- dataType: 'text',
- success: function(data) {
- console.log('success loading ' + url);
- try {
- var messages = propertiesFileReader.parse(data);
- } catch (e) {
- // We have no messages for this particular language code
- callback(false);
- return;
- }
- $.each(messages, function(key, val) {
- mw.messages.set(key, val);
- });
- callback(true);
- },
- error: function(xhr, status, err) {
- console.log('failed to load ' + url + ': ' + status + '; ' + err);
+ var remoteUrl = WLMConfig.GITHUB_MESSAGES + url;
+
+ function parseResponse( data ) {
+ var messages, success;
+ try {
+ messages = propertiesFileReader.parse( data );
+ $.each( messages, function( key, val ) {
+ mw.messages.set( key, val );
+ } );
+ success = true;
+ } catch ( e ) {
+ // We have no messages for this particular language code
+ success = false;
+ }
+
+ callback( success );
+ }
+ console.log( 'Loading messages from github: ' + remoteUrl );
+ $.ajax( { url: remoteUrl } ).done( parseResponse ).fail( function() {
+ console.log( 'Falling back to local messages: ' + url );
+ $.ajax( { url: url } ).done( parseResponse ).error( function( xhr, status, err ) {
+ console.log( 'failed to load ' + url + ': ' + status + '; ' + err );
// We seem to get "success" on file not found, which feels wrong...
// We kinda expect to get 404 errors or similar?
- callback(false);
- }
- });
+ callback( false );
+ } );
+ } );
}
function navigatorLang(success) {

0 comments on commit d537baa

Please sign in to comment.