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

Add compact option for compact dictionary output #484

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

txgk
Copy link

@txgk txgk commented Feb 16, 2023

Hi, first of all I would like to thank you for such wonderful project! It makes my translations really quick and allows me to return to reading straightaway without being distracted by overloaded translation services in the web browser.

In this issue I would like to resolve a little problem I ran into. For convenient reading of hieroglyphs, I increased the font size in my terminal and now it fits a slightly smaller number of lines than before and pretty often translate-shell output doesn't fit in one page, so I have to scroll terminal buffer within my tmux session which is quite tedious.

Let's take a look at output of trans -s zh-CN -t en 量:

量
(Liàng)

quantity

Definitions of 量
[ 简体中文 -> English ]

noun
    amount
        量, 额, 数量, 多少, 数目, 数字
    volume
        卷, 体积, 音量, 量, 额, 册
    quantity
        数量, 量, 份量, 额
    capacity
        容量, 量, 才能, 潜力, 器
    measure
        措施, 测度, 度量, 量, 度, 手段
    quantum
        量子, 量, 额, 限量
    estimate
        预算, 量, 揆
    mete
        量

verb
    amount
        量, 等于, 合计, 共计, 折合, 为数
    measure
        测量, 衡量, 测, 计量, 量, 衡
    estimate
        估计, 预计, 估, 估量, 量, 计量
    mete
        量

adjective
    quantitative
        量

量
    quantity, the amount, amount

As you can see this content takes a lot of terminal lines. It could be a significantly more compact if dictionary would place translation on one line with the definitions, e. g.:

    amount - 量, 额, 数量, 多少, 数目, 数字

instead of

    amount
        量, 额, 数量, 多少, 数目, 数字

So I decided to dig into the codebase of translate-shell and found a solution:

--- a/include/Translators/GoogleTranslate.awk
+++ b/include/Translators/GoogleTranslate.awk
@@ -430,9 +430,9 @@ function googleTranslate(text, sl, tl, hl,
 
                     r = r RS prettify("dictionary-word", ins(1, (article ? "(" article ") " : "") word, tl))
                     if (isRTL(il))
-                        r = r RS prettify("dictionary-explanation-item", ins(2, explanation, il))
+                        r = r " - " prettify("dictionary-explanation-item", ins(0, explanation, il))
                     else
-                        r = r RS ins(2, explanation)
+                        r = r " - " ins(0, explanation)
                 }
             }
         }

I tried to put this functionality into a command-line option to avoid disturbing users who are accustomed to the current broad output. I'm pretty sure I didn't do it 100% right, so I'll be happy to correct the patch of this MR to match the requirements of the project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant