Skip to content

Commit

Permalink
Loads of i18n and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MusikAnimal committed Mar 12, 2017
1 parent 0fa575f commit a972e8d
Show file tree
Hide file tree
Showing 51 changed files with 926 additions and 275 deletions.
6 changes: 3 additions & 3 deletions javascripts/langviews/langviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
<th>${$.i18n('unique-titles', this.outputData.titles.length)}</th>
<th>${totalBadgesMarkup}</th>
<th>${this.formatNumber(this.outputData.sum)}</th>
<th>${this.formatNumber(Math.round(this.outputData.average))} / ${$.i18n('day')}</th>`
<th>${this.formatNumber(Math.round(this.outputData.average))}</th>`
);
$('#output_list').html('');

Expand All @@ -334,10 +334,10 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
`<tr>
<th scope='row'>${index + 1}</th>
<td>${item.lang}</td>
<td><a href="${item.url}" target="_blank">${item.label}</a></td>
<td>${this.getPageLink(item.label, `${item.lang}.${this.baseProject}.org`)}</td>
<td>${badgeMarkup}</td>
<td><a target='_blank' href='${this.getPageviewsURL(`${item.lang}.${this.baseProject}.org`, item.label)}'>${this.formatNumber(item.sum)}</a></td>
<td>${this.formatNumber(Math.round(item.average))} / ${$.i18n('day')}</td>
<td>${this.formatNumber(Math.round(item.average))}</td>
</tr>`
);
});
Expand Down
12 changes: 7 additions & 5 deletions javascripts/redirectviews/redirectviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class RedirectViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
<th>${$.i18n('num-redirects', this.formatNumber(numRedirects), numRedirects)}</th>
<th>${$.i18n('num-sections', this.formatNumber(this.outputData.sectionCount), this.outputData.sectionCount)}</th>
<th>${this.formatNumber(this.outputData.sum)}</th>
<th>${this.formatNumber(Math.round(this.outputData.average))} / ${$.i18n('day')}</th>`
<th>${this.formatNumber(Math.round(this.outputData.average))}</th>`
);
$('#output_list').html('');

Expand All @@ -316,17 +316,19 @@ class RedirectViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
let sectionMarkup = '';

if (item.section) {
const sectionUrl = `${this.getPageURL(this.outputData.source)}#${encodeURIComponent(item.section.score())}`;
sectionMarkup = `<a href="${sectionUrl}" target="_blank">#${item.section}</a>`;
sectionMarkup = this.getPageLink(this.outputData.source, this.project, '#' + item.section, item.section);
}

$('#output_list').append(
`<tr>
<th scope='row'>${index + 1}</th>
<td><a href="${item.url}" target="_blank">${item.label}</a> ${isSource ? '(' + $.i18n('target') + ')' : ''}</td>
<td>
${this.getPageLink(item.label, `${this.project}.org`)}
${isSource ? '(' + $.i18n('target') + ')' : ''}
</td>
<td>${sectionMarkup}</a></td>
<td><a target='_blank' href='${this.getPageviewsURL(`${this.project}.org`, item.label)}'>${this.formatNumber(item.sum)}</a></td>
<td>${this.formatNumber(Math.round(item.average))} / ${$.i18n('day')}</td>
<td>${this.formatNumber(Math.round(item.average))}</td>
</tr>`
);
});
Expand Down
2 changes: 1 addition & 1 deletion javascripts/shared/list_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const ListHelpers = superclass => class extends superclass {
}

return `/pageviews?start=${startDate.format('YYYY-MM-DD')}&end=${endDate.format('YYYY-MM-DD')}` +
`&project=${project}&platform=${platform}&pages=${encodeURIComponent(page)}`;
`&project=${project}&platform=${platform}&pages=${encodeURIComponent(page.score()).replace("'", escape)}`;
}

/**
Expand Down
31 changes: 26 additions & 5 deletions javascripts/shared/pv.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,20 @@ class Pv extends PvConfig {
* Get a full link for the given page and project
* @param {string} page - page to link to
* @param {string} [project] - project link, defaults to `this.project`
* @param {string} [text] - Link text, defaults to page title
* @param {string} [section] - Link to a specific section on the page
* @return {string} HTML markup
*/
getPageLink(page, project) {
return `<a target="_blank" href="${this.getPageURL(page, project)}">${page.descore().escape()}</a>`;
getPageLink(page, project, text, section) {
let attrs = `target="_blank" href="${this.getPageURL(page, project)}${section ? '#' + section.score() : ''}"`;

if (this.isMultilangProject(project)) {
const projectLang = this.getProjectLang(project);

attrs += ` lang=${projectLang} dir="${this.config.rtlLangs.includes(projectLang) ? 'rtl' : 'ltr'}"`;
}

return `<a target="_blank" ${attrs}>${text || page.descore().escape()}</a>`;
}

/**
Expand All @@ -488,14 +498,24 @@ class Pv extends PvConfig {
/**
* Get the project name (without the .org)
*
* @returns {boolean} lang.projectname
* @returns {string} lang.projectname
*/
get project() {
const project = $(this.config.projectInput).val();
/** Get the first 2 characters from the project code to get the language */
return project ? project.toLowerCase().replace(/.org$/, '') : null;
}

/**
* Split project by . and get first result.
* Used to apply dir='rtl' on links to wikis that are RTL
* @param {string} [project] Project, defaults to this.project
* @returns {string} lang
*/
getProjectLang(project) {
return (project || this.project).split('.')[0];
}

/**
* get date format for the browser's locale
* @return {String} format to be passed to moment.format()
Expand Down Expand Up @@ -958,10 +978,11 @@ class Pv extends PvConfig {

/**
* Test if the current project is a multilingual project
* @param {String} [project] Project, defaults to this.project
* @returns {Boolean} is multilingual or not
*/
isMultilangProject() {
return new RegExp(`.*?\\.(${Pv.multilangProjects.join('|')})`).test(this.project);
isMultilangProject(project = this.project) {
return new RegExp(`.*?\\.(${Pv.multilangProjects.join('|')})`).test(project);
}

/**
Expand Down
1 change: 1 addition & 0 deletions javascripts/shared/pv_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class PvConfig {
platform: ['all-access', 'desktop', 'mobile-app', 'mobile-web'],
project: siteDomains
},
rtlLangs: ['ar', 'he', 'fa', 'ps', 'ur'],
pageAssessmentProjects: ['en.wikipedia', 'en.wikivoyage'],
pageAssessmentBadges: {
'en.wikipedia': {
Expand Down
4 changes: 2 additions & 2 deletions javascripts/topviews/topviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TopViews extends Pv {
</td>
<td>
<span class='topview-entry--background' style='top:${offsetTop}px; background:linear-gradient(${direction}, #EEE ${width}%, transparent ${width}%); opacity: 0.6'></span>
<a class='topview-entry--label' href="${this.getPageURL(item.article)}" target="_blank">${item.article}</a>
<div class='topview-entry--label'>${this.getPageLink(item.article, this.project)}</div>
</td>
<td class='topview-entry--edits'>${edits}</td>
<td class='topview-entry--editors'>${editors}</td>
Expand Down Expand Up @@ -324,7 +324,7 @@ class TopViews extends Pv {
project = $(this.config.projectInput).val();

return `/pageviews?start=${startDate}&end=${endDate}&project=${project}` +
`&platform=${platform}&pages=${encodeURIComponent(article)}`;
`&platform=${platform}&pages=${encodeURIComponent(article.score()).replace("'", escape)}`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion javascripts/userviews/userviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class UserViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
<td>${datestamp}</td>
<td>${this.formatNumber(item.size)}</td>
<td><a target='_blank' href='${this.getPageviewsURL(`${this.project}.org`, item.label)}'>${this.formatNumber(item.sum)}</a></td>
<td>${this.formatNumber(Math.round(item.average))} / ${$.i18n('day')}</td>
<td>${this.formatNumber(Math.round(item.average))}</td>
</tr>`
);
});
Expand Down
8 changes: 4 additions & 4 deletions public_html/_data_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
</ul>
</div>
</div>
<span class="chart-toggles">
<span class="pull-right chart-specific">
<span class="chart-toggles chart-specific">
<span class="pull-right">
<label class="logarithmic-scale">
<input class="logarithmic-scale-option" type="checkbox">
<?php echo $I18N->msg( 'logarithmic-scale' ); ?>
</label>
</span>
<span class="pull-right chart-specific">
<span class="pull-right">
<label class="begin-at-zero">
<input class="begin-at-zero-option" type="checkbox">
<?php echo $I18N->msg( 'begin-at-zero' ); ?>
</label>
</span>
<span class="pull-right chart-specific">
<span class="pull-right">
<label class="show-labels">
<input class="show-labels-option" type="checkbox">
<?php echo $I18N->msg( 'show-values' ); ?>
Expand Down
4 changes: 2 additions & 2 deletions public_html/_head.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function ( $filename ) {
$messageFiles
) ) );

$availableLanguages = array();
$availableLanguages = [];
foreach ( $languages as $lang ) {
$availableLanguages[$lang] = ucfirst( $I18N->getLangName( $lang ) );
}
Expand All @@ -39,7 +39,7 @@ function generateListMessage( $values ) {
}

// Adds a .rtl class to the <body> if a right-to-left language
if ( in_array( $I18N->getLang(), array( 'ar', 'he', 'fa', 'ps', 'ur' ) ) ) {
if ( in_array( $I18N->getLang(), [ 'ar', 'he', 'fa', 'ps', 'ur' ] ) ) {
$rtl = 'rtl';
} else {
$rtl = '';
Expand Down
7 changes: 5 additions & 2 deletions public_html/_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@
</div>
<div class="navbar-collapse collapse interapp-navigation">
<a class="home-link pull-left" href="<?php echo '/pageviews'; ?>"></a>
<ul class="interapp-links nav navbar-nav navbar-left">
<ol class="interapp-links nav navbar-nav navbar-left">
<?php $apps = [ 'pageviews', 'langviews', 'topviews', 'siteviews', 'massviews', 'redirectviews', 'userviews' ]; ?>
<?php if ( $rtl === 'rtl' ) { ?>
<?php $apps = array_reverse( $apps ); ?>
<?php } ?>
<?php foreach( $apps as $app ) { ?>
<?php $i18nName = $app === 'pageviews' ? '' : $app . '-'; ?>
<?php if ( $app === $currentApp ) { ?>
Expand All @@ -89,7 +92,7 @@
</li>
<?php } ?>
<?php } ?>
</ul>
</ol>
</div>
</nav>
<?php if ( $isAppPage ) { ?>
Expand Down
2 changes: 1 addition & 1 deletion public_html/_output.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<?php } ?>
<th>
<span>
<?php echo $I18N->msg( 'average' ); ?>
<?php echo $I18N->msg( 'daily-average' ); ?>
</span>
</th>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion public_html/application.css

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions public_html/application.js

Large diffs are not rendered by default.

57 changes: 48 additions & 9 deletions public_html/faq/application.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public_html/langviews/application.css

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions public_html/langviews/application.js

Large diffs are not rendered by default.

Loading

0 comments on commit a972e8d

Please sign in to comment.