diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-29 18:15:03 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-29 18:44:42 +0200 |
commit | 6a3271735186a2b4d3c500f4f60c0c03a12bdd2f (patch) | |
tree | e5ceaf01ba400b1ef552fbeec92919826200cd30 /music_sampler/helpers.py | |
parent | 7d6df771f603e9642047264f967525422ef09e99 (diff) | |
download | MusicSampler-6a3271735186a2b4d3c500f4f60c0c03a12bdd2f.tar.gz MusicSampler-6a3271735186a2b4d3c500f4f60c0c03a12bdd2f.tar.zst MusicSampler-6a3271735186a2b4d3c500f4f60c0c03a12bdd2f.zip |
Make music_sampler multilingual1.2.0
Diffstat (limited to 'music_sampler/helpers.py')
-rw-r--r-- | music_sampler/helpers.py | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/music_sampler/helpers.py b/music_sampler/helpers.py index 2249746..2199058 100644 --- a/music_sampler/helpers.py +++ b/music_sampler/helpers.py | |||
@@ -5,6 +5,8 @@ import os | |||
5 | import math | 5 | import math |
6 | import sounddevice as sd | 6 | import sounddevice as sd |
7 | import logging | 7 | import logging |
8 | import gettext | ||
9 | gettext.install('music_sampler') | ||
8 | Logger = logging.getLogger("kivy") | 10 | Logger = logging.getLogger("kivy") |
9 | 11 | ||
10 | from . import sysfont | 12 | from . import sysfont |
@@ -66,71 +68,76 @@ def parse_args(): | |||
66 | sys.argv.extend(["-c", "kivy:log_name:/tmp/music_sampler_%_.txt"]) | 68 | sys.argv.extend(["-c", "kivy:log_name:/tmp/music_sampler_%_.txt"]) |
67 | 69 | ||
68 | parser = argparse.ArgumentParser( | 70 | parser = argparse.ArgumentParser( |
69 | description="A Music Sampler application.", | 71 | description=_("A Music Sampler application."), |
70 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) | 72 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
71 | parser.add_argument("-c", "--config", | 73 | parser.add_argument("-c", "--config", |
72 | default="config.yml", | 74 | default="config.yml", |
73 | required=False, | 75 | required=False, |
74 | help="Config file to load") | 76 | help=_("Config file to load")) |
75 | parser.add_argument("-p", "--music-path", | 77 | parser.add_argument("-p", "--music-path", |
76 | default=".", | 78 | default=".", |
77 | required=False, | 79 | required=False, |
78 | help="Folder in which to find the music files") | 80 | help=_("Folder in which to find the music files")) |
79 | parser.add_argument("-d", "--debug", | 81 | parser.add_argument("-d", "--debug", |
80 | nargs=0, | 82 | nargs=0, |
81 | action=DebugModeAction, | 83 | action=DebugModeAction, |
82 | help="Print messages in console") | 84 | help=_("Print messages in console")) |
83 | parser.add_argument("-m", "--builtin-mixing", | 85 | parser.add_argument("-m", "--builtin-mixing", |
84 | action="store_true", | 86 | action="store_true", |
85 | help="Make the mixing of sounds manually\ | 87 | help=_("Make the mixing of sounds manually\ |
86 | (do it if the system cannot handle it correctly)") | 88 | (do it if the system cannot handle it correctly)")) |
87 | parser.add_argument("-l", "--latency", | 89 | parser.add_argument("-l", "--latency", |
88 | default="high", | 90 | default="high", |
89 | required=False, | 91 | required=False, |
90 | help="Latency: low, high or number of seconds") | 92 | help=_("Latency: low, high or number of seconds")) |
91 | parser.add_argument("-b", "--blocksize", | 93 | parser.add_argument("-b", "--blocksize", |
92 | default=0, | 94 | default=0, |
93 | type=int, | 95 | type=int, |
94 | required=False, | 96 | required=False, |
95 | help="Blocksize: If not 0, the number of frames to take\ | 97 | help=_("Blocksize: If not 0, the number of frames to take\ |
96 | at each step for the mixer") | 98 | at each step for the mixer")) |
97 | parser.add_argument("-f", "--frame-rate", | 99 | parser.add_argument("-f", "--frame-rate", |
98 | default=44100, | 100 | default=44100, |
99 | type=int, | 101 | type=int, |
100 | required=False, | 102 | required=False, |
101 | help="Frame rate to play the musics") | 103 | help=_("Frame rate to play the musics")) |
102 | parser.add_argument("-x", "--channels", | 104 | parser.add_argument("-x", "--channels", |
103 | default=2, | 105 | default=2, |
104 | type=int, | 106 | type=int, |
105 | required=False, | 107 | required=False, |
106 | help="Number of channels to use") | 108 | help=_("Number of channels to use")) |
107 | parser.add_argument("-s", "--sample-width", | 109 | parser.add_argument("-s", "--sample-width", |
108 | default=2, | 110 | default=2, |
109 | type=int, | 111 | type=int, |
110 | required=False, | 112 | required=False, |
111 | help="Sample width (number of bytes for each frame)") | 113 | help=_("Sample width (number of bytes for each frame)")) |
112 | parser.add_argument("-V", "--version", | 114 | parser.add_argument("-V", "--version", |
113 | action="version", | 115 | action="version", |
114 | help="Displays the current version and exits. Only use\ | 116 | help=_("Displays the current version and exits. Only use\ |
115 | in bundled package", | 117 | in bundled package"), |
116 | version=show_version()) | 118 | version=show_version()) |
117 | parser.add_argument("--device", | 119 | parser.add_argument("--device", |
118 | action=SelectDeviceAction, | 120 | action=SelectDeviceAction, |
119 | help="Select this sound device" | 121 | help=_("Select this sound device") |
120 | ) | 122 | ) |
121 | parser.add_argument("--list-devices", | 123 | parser.add_argument("--list-devices", |
122 | nargs=0, | 124 | nargs=0, |
123 | action=ListDevicesAction, | 125 | action=ListDevicesAction, |
124 | help="List available sound devices" | 126 | help=_("List available sound devices") |
125 | ) | 127 | ) |
126 | parser.add_argument("--no-focus-warning", | 128 | parser.add_argument("--no-focus-warning", |
127 | action='store_true', | 129 | action='store_true', |
128 | help="Don't show warning when focus is lost" | 130 | help=_("Don't show warning when focus is lost") |
131 | ) | ||
132 | parser.add_argument("-L", "--language", | ||
133 | required=False, | ||
134 | default="fr", | ||
135 | help=_("Select another language") | ||
129 | ) | 136 | ) |
130 | parser.add_argument('--', | 137 | parser.add_argument('--', |
131 | dest="args", | 138 | dest="args", |
132 | help="Kivy arguments. All arguments after this are interpreted\ | 139 | help=_("Kivy arguments. All arguments after this are interpreted\ |
133 | by Kivy. Pass \"-- --help\" to get Kivy's usage.") | 140 | by Kivy. Pass \"-- --help\" to get Kivy's usage.")) |
134 | 141 | ||
135 | args = parser.parse_args(argv) | 142 | args = parser.parse_args(argv) |
136 | 143 | ||
@@ -143,6 +150,10 @@ def parse_args(): | |||
143 | Config.sample_width = args.sample_width | 150 | Config.sample_width = args.sample_width |
144 | Config.builtin_mixing = args.builtin_mixing | 151 | Config.builtin_mixing = args.builtin_mixing |
145 | Config.no_focus_warning = args.no_focus_warning | 152 | Config.no_focus_warning = args.no_focus_warning |
153 | if args.language != 'en': | ||
154 | gettext.translation("music_sampler", | ||
155 | localedir=path() + '/locales', | ||
156 | languages=[args.language]).install() | ||
146 | if args.music_path.endswith("/"): | 157 | if args.music_path.endswith("/"): |
147 | Config.music_path = args.music_path | 158 | Config.music_path = args.music_path |
148 | else: | 159 | else: |
@@ -167,7 +178,7 @@ def show_version(): | |||
167 | with open(path() + ".pyinstaller_commit", "r") as f: | 178 | with open(path() + ".pyinstaller_commit", "r") as f: |
168 | return f.read() | 179 | return f.read() |
169 | else: | 180 | else: |
170 | return "option '-v' can only be used in bundled package" | 181 | return _("option '-V' can only be used in bundled package") |
171 | 182 | ||
172 | def duration_to_min_sec(duration): | 183 | def duration_to_min_sec(duration): |
173 | minutes = int(duration / 60) | 184 | minutes = int(duration / 60) |