Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite781d2f

Browse files
committed
Merge branch 'using-translations' into translation-preview
2 parentsa5431e6 +3c73d4d commite781d2f

File tree

13 files changed

+7299
-565
lines changed

13 files changed

+7299
-565
lines changed

‎.github/workflows/workflow.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ jobs:
2121
REACT_APP_FEEDBACK_GITHUB_TOKEN:${{ secrets.REACT_APP_FEEDBACK_GITHUB_TOKEN }}
2222
REACT_APP_SENTRY_DSN:https://37b1f01452b54bf4a0fe88656070998f@o871617.ingest.sentry.io/5824691
2323
REACT_APP_USE_FIREBASE_EMULATORS:'1'
24+
FUTURECODER_LANGUAGE:es
2425
run:./full_build.sh
2526
# - name: Test
27+
# env:
28+
# FUTURECODER_LANGUAGE: en
2629
# run: ./ci_test.sh
2730
# - name: Upload test artifacts
2831
# uses: actions/upload-artifact@v2

‎core/chapters/c04_for_loops.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class loop_exercise_1(ExerciseStep):
153153
"""
154154

155155
hints="""
156-
You should only use one print, since each print outputs on a different line.
156+
You should only use one`print`, since each print outputs on a different line.
157157
You will need to use `+`.
158158
"""
159159

‎core/chapters/c06_lists.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,8 @@ class append_vs_concatenate(VerbatimStep):
902902
903903
- **`append`**: Add an element to the end of the list. `nums.append(4)` changes the list to `[1, 2, 3, 4]`.
904904
- **`len`**: Returns the number of elements. `len(nums)` is `3`.
905-
- **`range`**: `range(n)` is an object similar to the list of numbers from0 to `n - 1`. That means it contains `n` numbers. In particular, `range(len(nums))` is like `[0, 1, 2]`, which are the indices of every element in `nums`.
906-
- **`subscripting`**: Get a value at an index. `nums[0]` is1, `nums[1]` is2, `nums[2]` is3.
905+
- **`range`**: `range(n)` is an object similar to the list of numbers from`0` to `n - 1`. That means it contains `n` numbers. In particular, `range(len(nums))` is like `[0, 1, 2]`, which are the indices of every element in `nums`.
906+
- **`[]` (subscripting/indexing)**: Get a value at an index. `nums[0]` is`1`, `nums[1]` is`2`, `nums[2]` is`3`.
907907
- **`+`**: Concatenates lists. `nums + [4, 5]` is `[1, 2, 3, 4, 5]`.
908908
909909
Note that `nums.append(4)` modifies the existing list `nums`, while `nums + [4, 5]` does not.

‎core/chapters/c09_functions.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def alert(string, level):
614614
Use `surround` for the spaces.
615615
Use `surround` for the exclamation marks.
616616
You're not allowed to combine several exclamation marks into one string, so call `surround` several times.
617-
That is, call surround once for each pair of exclamation marks.
617+
That is, call`surround` once for each pair of exclamation marks.
618618
So call `surround(..., '!')` several times.
619619
Use a loop to call it several times.
620620
Use `range(n)` to make your loop have `n` iterations.

‎core/generate_static_files.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def tarfile_filter(tar_info):
8080

8181
defmain():
8282
print("Generating files...")
83-
translation.set_language("es")
83+
translation.set_language(os.environ["FUTURECODER_LANGUAGE"])
8484
this_dir=Path(__file__).parent
8585
frontend=this_dir/"../frontend"
8686
frontend_src=frontend/"src"

‎core/translation.py‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
importbuiltins
55
importgettext
66
importjson
7+
importos
78
importre
89
frompathlibimportPath
910
fromtextwrapimportindent
1011

1112
importasttokens.util
1213
fromasttokensimportASTTokens
1314

15+
fromcore.runner.utilsimportis_valid_syntax
16+
1417
translation:gettext.GNUTranslations|None=None
1518
current_language=None
1619

@@ -47,6 +50,15 @@ def get(msgid, default):
4750
assertmsgid.startswith(("code_bits."))or"output_prediction_choices"inmsgid
4851
returndefault
4952

53+
ifos.environ.get("CHECK_INLINE_CODES"):
54+
inline1= {translate_code(c)forcininline_codes(default)}
55+
inline2=inline_codes(result)
56+
ifinline1!=inline2:
57+
print(msgid)
58+
print(sorted(inline1))
59+
print(sorted(inline2))
60+
print()
61+
5062
defreplace(match):
5163
block_num=match[1]
5264
assertisinstance(code_blocks,dict)
@@ -163,7 +175,40 @@ def code_bit(node_text):
163175

164176

165177
defget_code_bit(node_text):
166-
returnget(code_bit(node_text),node_text)
178+
result=get(code_bit(node_text),node_text)
179+
node1=ast.parse(node_text).body[0].value
180+
node2=ast.parse(result).body[0].value
181+
try:
182+
asserttype(node1)==type(node2)
183+
assertisinstance(node1, (ast.Name,ast.Str,ast.JoinedStr))
184+
forquotein ['"',"'"]:
185+
assertresult.startswith(quote)==node_text.startswith(quote)
186+
assertresult.endswith(quote)==node_text.endswith(quote)
187+
quote='f'+quote
188+
assertresult.startswith(quote)==node_text.startswith(quote)
189+
190+
ifisinstance(node1,ast.JoinedStr):
191+
parts1=fstring_parts(node1,node_text)
192+
parts2=fstring_parts(node2,result)
193+
assertparts2== {translate_code(part)forpartinparts1}
194+
195+
exceptAssertionError:
196+
message=f"Invalid translation from{node_text} to{result}"
197+
# print(message)
198+
raiseValueError(message)
199+
returnresult
200+
201+
202+
deffstring_parts(node,source):
203+
return {
204+
ast.get_source_segment(source,part.value)# noqa
205+
forpartinnode.values
206+
ifisinstance(part,ast.FormattedValue)
207+
}
208+
209+
210+
definline_codes(text):
211+
return {cforcinre.findall(r"`(.+?)`",text)ifis_valid_syntax(c)}
167212

168213

169214
defpyflakes_message(message_cls):

‎generate.sh‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
poetry run python -m translations.generate_po_file
5+
6+
export FIX_CORE_IMPORTS=1
7+
export FIX_TESTS=1
8+
9+
forlangin es en
10+
do
11+
export FUTURECODER_LANGUAGE=$lang
12+
poetry run python -m core.generate_static_files
13+
poetry run pytest tests/test_steps.py
14+
done

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp