Skip to content

Commit

Permalink
Merge pull request #1095 from shad-k/translate-mixin
Browse files Browse the repository at this point in the history
Add mixin to dedup definition of translateString [Fixes #979]
  • Loading branch information
samajammin authored Jun 8, 2020
2 parents 6f18945 + 5393f2d commit 18dd75e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 50 deletions.
53 changes: 25 additions & 28 deletions docs/.vuepress/components/BuildPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,19 @@
</template>

<script>
import { translate } from '../theme/utils/translations'
import { translateMixin } from '../theme/utils/translations'
const { inlineMd } = require('../theme/utils/inline-md')
export default {
mixins: [translateMixin],
methods: {
inlineMd: function(str) {
inlineMd: function (str) {
return inlineMd(str)
},
translateString: function(str) {
return translate(str, this.$lang)
langPath: function () {
return this.translateString('path')
},
langPath: function() {
return translate('path', this.$lang)
}
},
computed: {
templates() {
Expand All @@ -148,9 +145,9 @@ export default {
),
to: {
url: 'https://studio.ethereum.org/1',
text: this.translateString('page-build-hello-world-link-text')
text: this.translateString('page-build-hello-world-link-text'),
},
icon: ':wave:'
icon: ':wave:',
},
{
title: this.translateString('page-build-coin-contract-title'),
Expand All @@ -159,9 +156,9 @@ export default {
),
to: {
url: 'https://studio.ethereum.org/2',
text: this.translateString('page-build-coin-contract-link-text')
text: this.translateString('page-build-coin-contract-link-text'),
},
icon: ':key:'
icon: ':key:',
},
{
title: this.translateString('page-build-crypto-pizza-title'),
Expand All @@ -170,10 +167,10 @@ export default {
),
to: {
url: 'https://studio.ethereum.org/3',
text: this.translateString('page-build-crypto-pizza-link-text')
text: this.translateString('page-build-crypto-pizza-link-text'),
},
icon: ':pizza:'
}
icon: ':pizza:',
},
]
},
learningPlatforms() {
Expand All @@ -186,8 +183,8 @@ export default {
to: 'https://cryptozombies.io/',
img: {
src: '/ecosystem/crypto-zombie.png',
alt: 'CryptoZombies'
}
alt: 'CryptoZombies',
},
},
{
title: 'Ethernauts',
Expand All @@ -197,26 +194,26 @@ export default {
to: 'https://ethernaut.openzeppelin.com/',
img: {
src: '/ecosystem/oz.png',
alt: 'Open Zeppelin Ethernaut'
}
alt: 'Open Zeppelin Ethernaut',
},
},
{
title: 'Remix',
description: this.translateString('page-build-remix-description'),
to: 'https://remix.ethereum.org',
img: {
src: '/ecosystem/remix.png',
alt: 'Remix'
}
alt: 'Remix',
},
},
{
title: 'ChainShot',
description: this.translateString('page-build-chainshot-description'),
to: 'https://www.chainshot.com',
img: {
src: '/ecosystem/chainshot.png',
alt: 'ChainShot'
}
alt: 'ChainShot',
},
},
{
title: 'ConsenSys Academy',
Expand All @@ -226,12 +223,12 @@ export default {
to: 'https://consensys.net/academy/bootcamp/',
img: {
src: '/ecosystem/consensys.png',
alt: 'ConsenSys Academy'
}
}
alt: 'ConsenSys Academy',
},
},
]
}
}
},
},
}
</script>

Expand Down
11 changes: 4 additions & 7 deletions docs/.vuepress/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</template>

<script>
import { translate } from '../theme/utils/translations'
import { translateMixin } from '../theme/utils/translations'
export default {
computed: {
Expand Down Expand Up @@ -195,17 +195,14 @@ export default {
]
}
},
mixins: [translateMixin],
methods: {
translateString: function(str) {
return translate(str, this.$lang)
},
langPath: function() {
return translate('path', this.$lang)
return this.translateString('path')
},
contentVersion() {
return translate('version', this.$lang)
return this.translateString('version')
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions docs/.vuepress/theme/components/AlgoliaSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</template>

<script>
import { translate } from '../utils/translations'
import { translateMixin } from '../utils/translations'
export default {
name: 'AlgoliaSearchBox',
Expand Down Expand Up @@ -83,7 +83,7 @@ export default {
mounted() {
this.initialize(this.options, this.$lang)
},
mixins: [translateMixin],
methods: {
initialize(userOptions, lang) {
Promise.all([
Expand Down Expand Up @@ -124,10 +124,6 @@ export default {
update(options, lang) {
this.$el.innerHTML = this.$el.innerHTML // Needed to reset language index
this.initialize(options, lang)
},
translateString: function(str) {
return translate(str, this.$lang)
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions docs/.vuepress/theme/components/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

<script>
import { isActive, resolveNavLinkItem } from '../utils/util'
import { translate } from '../utils/translations'
import { translateMixin } from '../utils/translations'
import NavLink from './NavLink.vue'
import NavDropdown from './NavDropdown.vue'
import SearchBox from './SearchBox.vue'
Expand Down Expand Up @@ -142,11 +142,11 @@ export default {
darkOrLightModeText() {
const key = this.isDarkMode ? 'light-mode' : 'dark-mode'
return translate(key, this.$lang)
return this.translateString(key)
},
nav() {
const languagePath = translate('path', this.$lang)
const languagePath = this.translateString('path')
return this.$site.locales[languagePath].nav || []
},
Expand All @@ -168,16 +168,12 @@ export default {
return this.algolia && this.algolia.apiKey && this.algolia.indexName
}
},
mixins: [translateMixin],
methods: {
isActive,
handleSearchToggle() {
this.isSearchVisible = !this.isSearchVisible
},
translateString: function(str) {
return translate(str, this.$lang)
}
},
Expand Down
11 changes: 10 additions & 1 deletion docs/.vuepress/theme/utils/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,16 @@ const translate = (lookup, lang = 'en-US') => {
return translation || ''
}

const translateMixin = {
methods: {
translateString(str) {
return translate(str, this.$lang)
}
}
}

module.exports = {
translate,
translations
translations,
translateMixin
}

0 comments on commit 18dd75e

Please sign in to comment.