Skip to content

Commit 5a860ed

Browse files
committed
fix(cli): add deprecated language fallback support to CLI
fix: add error case for when a custom tld gives a 404 docs(cli): use correct lang code and valid tld
1 parent 0c13f02 commit 5a860ed

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Diff for: docs/cli.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Read "c'est la vie" in French to ``cestlavie.mp3``::
2424

2525
$ gtts-cli "c'est la vie" --lang fr --output cestlavie.mp3
2626

27-
Read '你好' to ``你好.mp3`` (in Mandarin, using google.cn)::
27+
Read '你好' to ``你好.mp3`` (in Mandarin, using google.com.hk)::
2828

29-
$ gtts-cli '你好' --tld cn --lang zh-cn --output 你好.mp3
29+
$ gtts-cli '你好' --tld .com.hk --lang zh-CN --output 你好.mp3
3030

3131
Read 'slow' slowly to ``slow.mp3``::
3232

Diff for: gtts/cli.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from gtts import gTTS, gTTSError, __version__
3-
from gtts.lang import tts_langs
3+
from gtts.lang import tts_langs, _fallback_deprecated_lang
44
import click
55
import logging
66
import logging.config
@@ -46,6 +46,9 @@ def validate_lang(ctx, param, lang):
4646
if ctx.params["nocheck"]:
4747
return lang
4848

49+
# Fallback from deprecated language if needed
50+
lang = _fallback_deprecated_lang(lang)
51+
4952
try:
5053
if lang not in tts_langs():
5154
raise click.UsageError(

Diff for: gtts/tts.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class gTTS:
4242
can produce different localized 'accents' for a given
4343
language. This is also useful when ``google.com`` might be blocked
4444
within a network but a local or different Google host
45-
(e.g. ``google.cn``) is not. Default is ``com``.
45+
(e.g. ``google.com.hk``) is not. Default is ``com``.
4646
lang (string, optional): The language (IETF language tag) to
4747
read the text in. Default is ``en``.
4848
slow (bool, optional): Reads text more slowly. Defaults to ``False``.
@@ -364,6 +364,8 @@ def infer_msg(self, tts, rsp=None):
364364

365365
if status == 403:
366366
cause = "Bad token or upstream API changes"
367+
elif status == 404 and tts.tld != "com":
368+
cause = "Unsupported tld '{}'".format(tts.tld)
367369
elif status == 200 and not tts.lang_check:
368370
cause = (
369371
"No audio stream in response. Unsupported language '%s'"

0 commit comments

Comments
 (0)