Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit d537baa7e73b522ffd6f8e165648f7862945ac2d 1 parent 5ca0936
@jrobson jrobson authored
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  assets/www/js/config.js
@@ -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
49 assets/www/js/l10n.js
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.