Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Internationalization bot comment #21

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
USER_NAME=vuejs-jp-bot
[email protected]

CHETSUMI_LANG=ja

[email protected]:vuejs-jp-bot/jp.vuejs.org.git
ORIGIN_REPO_DEFAULT_BRANCH=lang-ja

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ const RssFeedEmitter = require('rss-feed-emitter')
const Queue = require('queue')
const Github = require('./lib/github')
const Repo = require('./lib/repository')
const I18n = require('./lib/i18n')
// const Slack = require('./lib/slack')
const Utility = require('./lib/utility')

let i18n = new I18n()
let upstreamFeeder = new RssFeedEmitter()
let headFeeder = new RssFeedEmitter()
let github = new Github()
Expand Down Expand Up @@ -73,7 +75,7 @@ const setupHeadFeeder = () => {
const { data: result } = await github.searchIssue(remote, { hash })
let issueNo = null
if (result.total_count === 0) {
let body = `本家のドキュメントに更新がありました:page_facing_up:\r\nOriginal:${item.link}`
let body = `${i18n._t('body')} :page_facing_up:\r\nOriginal:${item.link}`
const { data: newIssue } = await github.createIssue(remote, { title: `[Doc]: ${Utility.removeHash(item.title)}`, body, labels: ['documentation'] })
issueNo = newIssue.number
Utility.log('S', `${item.title}: Issue created: ${newIssue.html_url}`)
Expand Down
25 changes: 25 additions & 0 deletions lib/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class I18n {
get translations() {
return {
en: {
body: 'There was an update of origin'
},
ja: {
body: '本家のドキュメントに更新がありました'
}
}
}
get languages() {
return Object.keys(this.translations)
}

constructor (lang=null) {
this.language = this.languages.includes(lang || process.env.CHETSUMI_LANG) ? (lang || process.env.CHETSUMI_LANG) : 'en'
}

_t(key){
return this.translations[this.language][key]
}
}

module.exports = I18n
11 changes: 11 additions & 0 deletions test/lib/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const assert = require('assert')
const I18n = require('../../lib/i18n')

describe('i18n', function () {
describe('_t()', function() {
it('returns translated text', function () {
const i18n = new I18n('ja')
assert(i18n._t('body') === '本家のドキュメントに更新がありました')
})
})
})
4 changes: 2 additions & 2 deletions test/lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const Repo = require('../../lib/repository')

describe('Repository', function () {
let origin = {
url: '[email protected]:re-fort/che-tsumi.git',
owner: 're-fort',
url: '[email protected]:vuejs-jp/che-tsumi.git',
owner: 'vuejs-jp',
name: 'che-tsumi',
defaultBranch: 'master',
}
Expand Down