Skip to content

Commit

Permalink
Merge pull request #951 from slidewiki/master
Browse files Browse the repository at this point in the history
Update release with translation fixes
  • Loading branch information
kadevgraaf authored Jul 23, 2018
2 parents cefa59c + fa95e6e commit 3642055
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 36 deletions.
4 changes: 1 addition & 3 deletions actions/loadDeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import loadLikes from './activityfeed/loadLikes';
import PermissionsStore from '../stores/PermissionsStore';
import loadContributors from './loadContributors';
import loadForks from './permissions/loadForks';
import changeCurrentLanguage from './translation/changeCurrentLanguage';
import loadDeckTranslations from './translation/loadDeckTranslations';
import validateUsedLanguage from './translation/validateUsedLanguage';
import loadNodeTranslations from './translation/loadNodeTranslations';

Expand Down Expand Up @@ -121,7 +119,7 @@ export default function loadDeck(context, payload, done) {
// need to set this for some reason otherwise deck tree does not reload on language change
if (languageWillChange) {
if (payloadCustom.navigate) {
payloadCustom.navigate.runFetchTree = true;
payloadCustom.navigate.runFetchTree = true;
} else {
payloadCustom.navigate = { runFetchTree : true };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AttachDeckList extends React.Component {
let deckCreatorid = deck.deckCreatorid === undefined ? this.props.user.userId : deck.deckCreatorid;
let deckCreator = deck.deckCreator === undefined ? this.props.user.username:deck.deckCreator;
let deckDate = CustomDate.format(deck.creationDate, 'Do MMMM YYYY');
let deckLanguageCode = deck.language === undefined ? 'en' : deck.language;
let deckLanguageCode = deck.language;
let deckLanguage = deckLanguageCode === undefined ? '' : getLanguageName(deckLanguageCode);
// default English
deckLanguage = (deckLanguage === '' ? 'English' : deckLanguage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class DeckViewPanel extends React.Component {
const originCreator = this.props.DeckViewStore.originCreatorData.username;
if (deckData.language) deckData.language = deckData.language.substring(0, 2);

let deckLanguageCode = deckData.language === undefined ? 'en' : deckData.language;
let deckLanguageCode = deckData.language;
let deckLanguage = deckLanguageCode === undefined ? '' : getLanguageName(deckLanguageCode);
// default English
deckLanguage = (deckLanguage === '' ? 'English' : deckLanguage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class DeckTranslationsModal extends React.Component {
&& !compareLanguageCodes(current, this.props.TranslationStore.originLanguage))
arr.push({key: current, value: current, text: getLanguageNativeName(current)});
return arr;
}, []).sort((a, b) => a.text > b.text);
}, []).sort((a, b) => (a.text > b.text) ? 1 : -1);
}

let btnMessage = this.context.intl.formatMessage(messages.translate);
Expand Down
24 changes: 15 additions & 9 deletions components/Deck/InfoPanel/InfoPanelInfoView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ class InfoPanelInfoView extends React.Component {
super(props);
this.messages = defineMessages({
language:{
id: 'ContentActionsHeader.language',
id: 'InfoPanelInfoView.language',
defaultMessage:'Language'
},
selectLanguage:{
id: 'ContentActionsHeader.selectLanguage',
id: 'InfoPanelInfoView.selectLanguage',
defaultMessage:'Select language'
},
viewLanguage:{
id: 'ContentActionsHeader.viewLanguage',
id: 'InfoPanelInfoView.viewLanguage',
defaultMessage:'You are viewing this in language'
},
translation:{
id: 'ContentActionsHeader.translation',
id: 'InfoPanelInfoView.translation',
defaultMessage:'Translation'
},
current:{
id: 'ContentActionsHeader.current',
id: 'InfoPanelInfoView.current',
defaultMessage:'Current'
},
alsoAvailableIn:{
id: 'ContentActionsHeader.alsoAvailableIn',
id: 'InfoPanelInfoView.alsoAvailableIn',
defaultMessage:'Also available in'
},
});
Expand Down Expand Up @@ -215,6 +215,9 @@ class InfoPanelInfoView extends React.Component {
// put the current (but unavailable) language first
languages.unshift(this.props.TranslationStore.currentLang);
}
languages = languages.filter((elem, pos) => {
return languages.indexOf(elem) === pos;
});
let languageOptions = languages.map((t) => ({
text: getLanguageName(t) + (t === primaryLanguage ? ' (primary)' : ''),
value: t,
Expand Down Expand Up @@ -254,12 +257,15 @@ class InfoPanelInfoView extends React.Component {
});
translationOptions = translationOptions.filter((a) => a !== undefined);

let currentLanguageName = getLanguageName(this.props.TranslationStore.currentLang);

return (
<div className="ui container" ref="infoPanel" role="complementary">
<div className="ui top attached icon buttons menu">
<Dropdown pointing="top left" disabled={languageOptions.length < 2 && !canEdit}
button basic className="attached" style={{textAlign: 'center'}}
trigger={<h5 className='ui small header'>{this.context.intl.formatMessage(this.messages.selectLanguage)}: <i className={currentLangIconName + ' flag'} style={{marginRight: 0, verticalAlign: 'middle'}}></i> ({getLanguageName(this.props.TranslationStore.currentLang)}) </h5>} icon={null}
trigger={<h5 className='ui small header'>{this.context.intl.formatMessage(this.messages.selectLanguage)}: <i className={currentLangIconName + ' flag'} style={{marginRight: 0, verticalAlign: 'middle'}}></i> {currentLanguageName ? ('(' + currentLanguageName + ')') : ''}</h5>}
icon={null}
aria-label="Select language" data-tooltip="Select language"
defaultValue={activeLanguage} options={languageOptions} onChange={this.changeCurrentLanguage.bind(this)} />
{/*
Expand Down Expand Up @@ -296,7 +302,7 @@ class InfoPanelInfoView extends React.Component {
<Button role="button" data-tooltip="Add translation"
onClick={this.addNodeTranslation.bind(this)}
aria-label="Add translation" aria-required
tabIndex="0" >
tabIndex="0" attached basic >
{currentLangIconName === 'icon' ? <Icon name='flag' /> : <Flag name={currentLangIconName} />}
{getLanguageName(this.props.TranslationStore.currentLang)}
</Button>
Expand All @@ -305,7 +311,7 @@ class InfoPanelInfoView extends React.Component {
: null
}
{(language !== activeLanguage) ?
<div className="ui selection list">
<div className="ui list">
<h5 className="ui small header">{this.context.intl.formatMessage(this.messages.viewLanguage)}:</h5>
<TranslationItem language={language} primary={this.props.TranslationStore.translations.length && language === primaryLanguage}
selector={this.props.DeckTreeStore.selector.toJS()} slug={this.props.DeckTreeStore.slug} clickable={language !== primaryLanguage} />
Expand Down
45 changes: 30 additions & 15 deletions components/Deck/InfoPanel/TranslationItem.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React from 'react';
import {NavLink} from 'fluxible-router';
import PropTypes from 'prop-types';
import {Button, Icon, Flag} from 'semantic-ui-react';
import {navigateAction} from 'fluxible-router';
import qs from 'querystring';

import {getLanguageName} from '../../../common';
import {flagForLocale} from '../../../configs/locales';

class TranslationItem extends React.Component {
directToTranslation(href, e) {
e.preventDefault();
this.context.executeAction(navigateAction, { url: href });
}

render() {
let href = '';
if (this.props.clickable) {
Expand All @@ -20,24 +26,33 @@ class TranslationItem extends React.Component {

let flagName = flagForLocale(this.props.language);
let iconName = flagName ? flagName + ' flag': 'flag icon';
let text = getLanguageName(this.props.language) + (this.props.primary ? ' (primary)' : '');

return (this.props.clickable === true) ?
<NavLink className="item" href={href} activeElement='div'>
<div className="content">
<div className="header">
<i className={iconName}></i>{getLanguageName(this.props.language)} { this.props.primary ? '(primary)' : ''}
</div>
</div>
</NavLink>
let node = (this.props.clickable === true) ?

<Button role="button" data-tooltip={text}
onClick={this.directToTranslation.bind(this, href)}
aria-label={text} aria-required
tabIndex="0" attached basic >
{iconName === 'flag icon' ? <Icon name='flag' /> : <Flag name={flagName} />}{text}
</Button>
:
<div className="item">
<div className="content">
<div className="header">
<i className={iconName}></i>{getLanguageName(this.props.language)} { this.props.primary ? '(primary)' : ''}
</div>
<div className="content">
<div className="header">
{iconName === 'flag icon' ? <Icon name='flag' /> : <Flag name={flagName} />}{text}
</div>
</div>;

return (
<div className="item">
{node}
</div>
);
}
}

TranslationItem.contextTypes = {
executeAction: PropTypes.func.isRequired
};

export default TranslationItem;
4 changes: 2 additions & 2 deletions components/Deck/TreePanel/TreePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class TreePanel extends React.Component {
//if it is a slide, also add ID of slide
presLocation += this.props.DeckTreeStore.selector.toJS().sid;// + '/';
}
if (this.props.TranslationStore.inTranslationMode && this.props.TranslationStore.currentLang) {
presLocation += '?language=' + this.props.TranslationStore.currentLang;
if (this.props.TranslationStore.currentLang || this.props.TranslationStore.treeLanguage) {
presLocation += '?language=' + (this.props.TranslationStore.currentLang || this.props.TranslationStore.treeLanguage);
}
return presLocation;
}
Expand Down
18 changes: 16 additions & 2 deletions intl/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -1204,5 +1204,19 @@
"UserRegistrationSocial.email": "Email *",
"UserRegistrationSocial.signup": "Sign Up",
"UserRegistrationSocial.account": "I can not access my account",
"UserRegistrationSocial.cancel": "Cancel"
}
"UserRegistrationSocial.cancel": "Cancel",
"DeckTranslationsModal.header": "Start new deck translations",
"DeckTranslationsModal.chooseLanguage": "Choose the target language...",
"DeckTranslationsModal.startTranslation": "Create a new translation:",
"DeckTranslationsModal.startTranslationSearchOptions": " (start typing to find your language in its native name)",
"DeckTranslationsModal.cancel": "Cancel",
"DeckTranslationsModal.translate": "Create translation",
"DeckTranslationsModal.originLanguage": "Original Language:",
"DeckTranslationsModal.switchSR": "Create a new deck translation",
"InfoPanelInfoView.language": "Language",
"InfoPanelInfoView.selectLanguage": "Select language",
"InfoPanelInfoView.viewLanguage": "You are viewing this in language",
"InfoPanelInfoView.translation": "Translation",
"InfoPanelInfoView.current": "Current",
"InfoPanelInfoView.alsoAvailableIn": "Also available in"
}
2 changes: 0 additions & 2 deletions stores/TranslationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ class TranslationStore extends BaseStore {
let primaryVariant = payload.translations.find((v) => !!v.original);
if (primaryVariant) {
this.originLanguage = primaryVariant.language.replace('_', '-');
} else {
this.originLanguage = 'en';
}

// update translations
Expand Down

0 comments on commit 3642055

Please sign in to comment.