Skip to content

Commit

Permalink
Translation to solovyina (#22)
Browse files Browse the repository at this point in the history
* migrate to Solovyina

* update: README description with new assets

* update: tests for migration to Solovyina

* update: minor README changes — upcase lang names

* add: Learning mode video to README
  • Loading branch information
dev99problems authored Sep 18, 2022
1 parent 8efad1d commit 618e02c
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 114 deletions.
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<a src="https://www.npmjs.com/package/alfred-translayta"><img src="https://img.shields.io/npm/v/alfred-translayta?color=yellow" /></a>


> **Translate** with Google Translate in Alfred (*en-ru* / *ru-en*). **Save** to favorites. Finally, **learn** the words.
> **Translate** with Google Translate in Alfred (*en-uk* / *uk-en*). **Save** to favorites. Finally, **learn** the words.
![](screenshots/dir.jpg)

Alfred Translayta is an Alfred workflow, which lets you easily translate en-ru, ru-en pairs, add words to favorites and have convenient way to review and memorize them later.
Alfred Translayta is an Alfred workflow, which lets you easily translate 🇬🇧 to 🇺🇦, 🇺🇦 to 🇬🇧 pairs, add words to favorites and have convenient way to review and memorize them later.

## Features
### Translation
Expand All @@ -23,7 +23,7 @@ Alfred Translayta is an Alfred workflow, which lets you easily translate en-ru,
* Auto save favorites to a file on disk

## Prerequisites
You need [Node.js 12+](https://nodejs.org) and Alfred 3 or 4 with the paid [Powerpack](https://www.alfredapp.com/powerpack/) upgrade.
You need [Node.js 14+](https://nodejs.org) and Alfred 3 or 4 with the paid [Powerpack](https://www.alfredapp.com/powerpack/) upgrade.

## Install
```
Expand All @@ -34,7 +34,7 @@ $ npm install --global alfred-translayta

Open Alfred and type `t` **or** press `Cmd+Shift+K` and:
* **to get translation**:
- start typing words or phrases in english or russian
- start typing words or phrases in English or Ukrainian
* **to get previous translation from cache**:
- press `spacebar`
* **access the favorites**:
Expand All @@ -52,30 +52,21 @@ Open Alfred and type `t` **or** press `Cmd+Shift+K` and:

## Screenshots

![](screenshots/direction.jpg)
**Auto** detection of **translation direction**

![](screenshots/previous-and-autocorrection.jpg)
![](screenshots/direction.jpg)

![](screenshots/learning-mode.jpg)
**Auto correction** of misspelled words

## How it is different
There are a lot of more popular alfred workflows for translation.
I really like 2 of them:
* [alfred-translate](https://github.com/podgorniy/alfred-translate) — ideological inspiration (`python` + `yandex translate`). The problem for me here is all `yandex` services are restricted in Ukraine. Plus some `python` errors after a few translations while using VPN(maybe this is just a local problem).
* [alfred-polyglot](https://github.com/nikersify/alfred-polyglot) — technical inspiration (`node` + `google translate`). **Alfred-polyglot** is really cool, you can translate to any language or set default translation pair, but the translations are restricted to only 1 option and really often it was not a best fit.
![](screenshots/autocorrection.jpg)

> The best code is no code at all
**Learning Mode**

**Why another solution?** It was an idea to mix both solutions and to get the best features of each: auto lang. detection, multiple options for translation and of course `favorites list`.
https://user-images.githubusercontent.com/6503508/190931908-f900f9da-8299-43e9-bb10-633299b817ed.mov

Moreover, `favorites` was the main feature I needed so bad. There are plenty of difficult words for me, `which I translate over and over and still can't remember their meaning and translation`. Instead, I would really like to have a place for all these words, which I could access even when my laptop is offline. So here it is!

## Testimonials

**Tech**
Inspired by [alfred-translate](https://github.com/podgorniy/alfred-translate) and [alfred-polyglot](https://github.com/nikersify/alfred-polyglot).
Based on [Alfy](https://github.com/sindresorhus/alfy) and [google-translate-api](https://github.com/vitalets/google-translate-api)

**Visual**
All icons are taken from [flaticon.com](https://www.flaticon.com/), so many kudos and thanks to [the authors](/icons/testimonials.md)

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alfred-translayta",
"version": "1.1.1",
"description": "Alfred workflow, which translates in ru-en/en-ru directions, save words to favorites.",
"version": "2.0.0",
"description": "Alfred workflow, which translates in uk-en/en-uk directions, save words to favorites.",
"main": "index.js",
"scripts": {
"postinstall": "alfy-init",
Expand All @@ -19,7 +19,7 @@
"url": "https://twitter.com/dev99problems"
},
"engines": {
"node": ">=12"
"node": ">=14"
},
"keywords": [
"alfred",
Expand Down
Binary file added screenshots/autocorrection.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/dir.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/direction.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshots/learning-mode.jpg
Binary file not shown.
Binary file added screenshots/learning-mode.mov
Binary file not shown.
Binary file removed screenshots/previous-and-autocorrection.jpg
Binary file not shown.
12 changes: 6 additions & 6 deletions src/__tests__/intl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ describe('intl', () => {
actionTip: 'to access favorites list enter "."'
})

expect(getActionTranslations('addToFavorites', 'ru')).toEqual({
action: '/добавить в избранное',
actionTip: 'получить доступ к списку избранного можно набрав "."'
expect(getActionTranslations('addToFavorites', 'uk')).toEqual({
action: '/додати в обране',
actionTip: 'переглянути обране можна натиснувши "."'
})

expect(getActionTranslations('save', 'en')).toEqual({
action: '/save',
actionTip: 'save updated translation'
})

expect(getActionTranslations('save', 'ru')).toEqual({
action: '/сохранить',
actionTip: 'сохранит обновленный перевод'
expect(getActionTranslations('save', 'uk')).toEqual({
action: '/зберегти',
actionTip: 'зберегти зміни'
})
})
})
Expand Down
74 changes: 37 additions & 37 deletions src/__tests__/output.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('output', () => {
describe('pronunciation', () => {
test('adds "pronunciation" next to translation if there is one', () => {
// originalInput = 'indeed'
const translation = 'верно'
const translation = 'вірно'
const pronunciation = 'inˈdēd'
const targetLang = 'en'

Expand All @@ -43,14 +43,14 @@ describe('output', () => {
)

expect(mainTranslation).toEqual({
title: 'верно [inˈdēd]',
title: 'вірно [inˈdēd]',
subtitle: 'best fit translation'
})
})

test('returns only translation, if no pronunciation found', () => {
// originalInput = 'indeed'
const translation = 'верно'
const translation = 'вірно'
const pronunciation = undefined
const targetLang = 'en'

Expand All @@ -61,18 +61,18 @@ describe('output', () => {
)

expect(mainTranslation).toEqual({
title: 'верно',
title: 'вірно',
subtitle: 'best fit translation'
})
})
})

describe('shows translation and tip in subtitle in "targetLang" and pronunciation in "sourceLang"', () => {
test('for en-ru direction', () => {
test('for en-uk direction', () => {
// originalInput = 'dwell'
const translation = 'жить'
const translation = 'мешкати'
const pronunciation = 'dwell'
const targetLang = 'ru'
const targetLang = 'uk'

const mainTranslation = formatMainTranslation(
translation,
Expand All @@ -82,17 +82,17 @@ describe('output', () => {
const hintLang = getStrLanguage(mainTranslation.subtitle)

expect(mainTranslation).toEqual({
title: 'жить [dwell]',
subtitle: 'найболее подходящий перевод'
title: 'мешкати [dwell]',
subtitle: 'накрайщий переклад'
})

expect(hintLang).toBe('ru')
expect(hintLang).toBe('uk')
})

test('for ru-en direction', () => {
// originalInput = 'обитать'
test('for uk-en direction', () => {
// originalInput = 'мешкати'
const translation = 'dwell'
const pronunciation = "obitat'"
const pronunciation = 'meshkaty'
const targetLang = 'en'

const mainTranslation = formatMainTranslation(
Expand All @@ -103,7 +103,7 @@ describe('output', () => {
const hintLang = getStrLanguage(mainTranslation.subtitle)

expect(mainTranslation).toEqual({
title: "dwell [obitat']",
title: 'dwell [meshkaty]',
subtitle: 'best fit translation'
})

Expand All @@ -116,30 +116,30 @@ describe('output', () => {
test('prepares other translations to alfy-output format of {title: translation}', () => {
const translations = [
'замок',
'дворец',
'ладья',
'твердыня',
'рокировка',
'убежище'
'контейнер',
'сховище',
'палац',
'тура',
'фортеця'
]

const formattedOtherTranslations = formatOtherTranslations(translations)

expect(formattedOtherTranslations).toEqual([
{
title: 'дворец'
title: 'контейнер'
},
{
title: 'ладья'
title: 'сховище'
},
{
title: 'твердыня'
title: 'палац'
},
{
title: 'рокировка'
title: 'тура'
},
{
title: 'убежище'
title: 'фортеця'
}
])
})
Expand All @@ -155,14 +155,14 @@ describe('output', () => {
test('prepares auto corrected value to alfy-output format', () => {
// originalInput = 'casle'
const correctedValue = 'castle'
const targetLang = 'ru'
const targetLang = 'uk'

const autoCorrectedItem = formatAutoCorrection(correctedValue, targetLang)
const hintLang = getStrLanguage(autoCorrectedItem.subtitle)

expect(autoCorrectedItem).toEqual({
title: 'castle',
subtitle: 'возможно вы имели ввиду ⤴️',
subtitle: 'можливо, ви мали на увазі ⤴️',
autocomplete: 'castle',
icon: { path: './icons/question.png' }
})
Expand All @@ -175,14 +175,14 @@ describe('output', () => {
describe('formatLastSearch', () => {
test('prepares last searched input to alfy-output format', () => {
const lastUserInput = 'dog'
const targetLang = 'ru'
const targetLang = 'uk'

const lastSearchItem = formatLastSearch(lastUserInput, targetLang)
const hintLang = getStrLanguage(lastSearchItem.subtitle)

expect(lastSearchItem).toEqual({
title: 'dog',
subtitle: 'предыдущий запрос',
subtitle: 'попередній запит',
icon: { path: './icons/history.png' }
})

Expand All @@ -197,13 +197,13 @@ describe('output', () => {
const translation = 'замок'
const otherTranslations = [
'замок',
'дворец',
'ладья',
'твердыня',
'рокировка',
'убежище'
'контейнер',
'сховище',
'палац',
'тура',
'фортеця'
]
const targetLang = 'ru'
const targetLang = 'uk'

const addToFavsItem = addToFavoritesAction(
userInput,
Expand All @@ -219,11 +219,11 @@ describe('output', () => {
console.log('otherTranslationsInArg', otherTranslationsInArg)

expect(addToFavsItem).toEqual({
title: '/добавить в избранное',
subtitle: 'получить доступ к списку избранного можно набрав "."',
title: '/додати в обране',
subtitle: 'переглянути обране можна натиснувши "."',
icon: { path: './icons/bookmark.png' },
arg:
'{"alfredworkflow":{"variables":{"action":"add","word":"castle","translations":"замок, дворец, ладья, твердыня, рокировка, убежище"}}}'
'{"alfredworkflow":{"variables":{"action":"add","word":"castle","translations":"замок, контейнер, сховище, палац, тура, фортеця"}}}'
})

expect(titleLang).toBe(targetLang)
Expand Down
22 changes: 11 additions & 11 deletions src/__tests__/rawGTranslateRes.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ exports.responseMock = {
[['замок', null, null, null, [['замок', [4, 5, 1]]]]]
]
],
'ru',
'uk',
1,
'en',
['castle', 'en', 'ru', true]
['castle', 'en', 'uk', true]
],
null,
[
Expand Down Expand Up @@ -96,39 +96,39 @@ exports.responseMock = {
true
],
[
'дворец',
'палац',
null,
['palace', 'castle', 'mansion', 'chateau', 'mansion house'],
2,
true
],
['ладья', null, ['rook', 'castle', 'shallop', 'ferry'], 3, true],
['тура', null, ['rook', 'castle', 'shallop', 'ferry'], 3, true],
[
'твердыня',
'фортеця',
null,
['stronghold', 'citadel', 'castle', 'fastness'],
3,
true
],
['рокировка', null, ['castling', 'castle'], 3, true],
['рокіровка', null, ['castling', 'castle'], 3, true],
[
'убежище',
'сховище',
null,
['asylum', 'refuge', 'shelter', 'haven', 'sanctuary', 'castle'],
3,
true
]
],
'ru',
'uk',
'en'
],
[
'verb',
[
['рокировать', null, ['castle'], 3, true],
['рокироваться', null, ['castle'], 3, true]
['рокірувати', null, ['castle'], 3, true],
['рокіруватись', null, ['castle'], 3, true]
],
'ru',
'uk',
'en'
]
],
Expand Down
Loading

0 comments on commit 618e02c

Please sign in to comment.