Jdrewniak has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/383338 )
Change subject: Checking if l10n available before translating page
......................................................................
Checking if l10n available before translating page
Bug: T171647
Change-Id: If3943e2d374c4b14dc6a40b53d405d7b51157f14
---
M dev/wikipedia.org/assets/js/page-localized.js
M dev/wikipedia.org/assets/js/polyfills.js
M dev/wikipedia.org/assets/js/topten-localized.js
3 files changed, 26 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/portals
refs/changes/38/383338/1
diff --git a/dev/wikipedia.org/assets/js/page-localized.js
b/dev/wikipedia.org/assets/js/page-localized.js
index 0cbefa1..fb1ba47 100644
--- a/dev/wikipedia.org/assets/js/page-localized.js
+++ b/dev/wikipedia.org/assets/js/page-localized.js
@@ -1,4 +1,4 @@
-/* global wmTest, translationsHash, mw, wmL10nVisible, rtlLangs */
+/* global wmTest, translationsHash, mw, wmL10nVisible, rtlLangs,
isTranslationAvailable */
/**
* This script localizes the page text.
@@ -13,7 +13,7 @@
( function ( wmTest, translationsHash, mw, rtlLangs ) {
- var primaryLang = wmTest.userLangs[ 0 ],
+ var primaryLang = isTranslationAvailable( wmTest.userLangs[ 0 ] ),
storedTranslationHash,
storedTranslations,
l10nReq,
@@ -39,7 +39,7 @@
return ( translationsHash === storedHash ) ? storedHash : false;
}
- if ( wmTest.userLangs[ 0 ] === 'en' ) {
+ if ( primaryLang === 'en' ) {
wmL10nVisible.makeVisible();
return;
}
diff --git a/dev/wikipedia.org/assets/js/polyfills.js
b/dev/wikipedia.org/assets/js/polyfills.js
index 2ceb0a3..eb01b49 100644
--- a/dev/wikipedia.org/assets/js/polyfills.js
+++ b/dev/wikipedia.org/assets/js/polyfills.js
@@ -293,6 +293,27 @@
}
/**
+ * Checks if a translation for the users language is available.
+ * If not, then returns 'en' as the language code since that's the
+ * language the page is initially rendered in.
+ *
+ * @param {string} lang
+ * @return {string}
+ */
+function isTranslationAvailable( lang ) {
+ var langLc = lang.toLowerCase();
+ if ( availableLanguages.indexOf( langLc ) >= 0 ) {
+ return langLc;
+ } else if ( availableLanguages.indexOf( getIso639( langLc ) ) >= 0 ) {
+ return getIso639( langLc );
+ } else {
+ // if translations are not available, fallback to default
server-renderd 'en' version.
+ return 'en';
+ }
+}
+
+
+/**
* Detects reported or approximate device pixel ratio.
* * 1.0 means 1 CSS pixel is 1 hardware pixel
* * 2.0 means 1 CSS pixel is 2 hardware pixels
diff --git a/dev/wikipedia.org/assets/js/topten-localized.js
b/dev/wikipedia.org/assets/js/topten-localized.js
index 161bb55..f67cf01 100644
--- a/dev/wikipedia.org/assets/js/topten-localized.js
+++ b/dev/wikipedia.org/assets/js/topten-localized.js
@@ -1,4 +1,4 @@
-/* global wmTest, translationsHash, wmL10nVisible, rtlLangs */
+/* global wmTest, translationsHash, wmL10nVisible, rtlLangs,
isTranslationAvailable */
/**
* This code was used to localize the top-ten language links
* for the A/B test titled "A/B test: browser language detection"
@@ -83,7 +83,7 @@
function mergeNewTopLinkLangs() {
var pl, plIndex, plExists, plRightSpot;
for ( i = 0; i < preferredLanguages.length; i++ ) {
- pl = preferredLanguages[ i ];
+ pl = isTranslationAvailable( preferredLanguages[ i ] );
plIndex = topLinkLangs.indexOf( pl );
plExists = plIndex >= 0;
plRightSpot = plIndex === i;
--
To view, visit https://gerrit.wikimedia.org/r/383338
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3943e2d374c4b14dc6a40b53d405d7b51157f14
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/portals
Gerrit-Branch: master
Gerrit-Owner: Jdrewniak <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits