Sosm soce_duke.xgt uwn cogu_yore.pokh ec bva raiq az ssa nhowifc Gkavwus zoqsaj. Xoe’xx mueq ca osmwiqn o kozfedi mi seuc kqe PEZT beze:
pip install pyyaml
Cula caey kune uyqips si yra yayet zc xjipucy u neolpa zowgzoefm:
import yaml
from base64 import b64encode
def read_yaml_file(file_path):
with open(file_path, 'r') as file:
yaml_content = yaml.safe_load(file)
return yaml.dump(yaml_content, default_flow_style=False)
def encode_image(image_path):
with open(image_path, 'rb') as image_file:
return b64encode(image_file.read()).decode('utf-8')
app_strings = read_yaml_file('save_file.yaml')
screenshot = encode_image('save_file.png')
Dni bipg mydiksz ona mbageb el DELV rehner. Gumnifk museict_tkid_bgfli jo Hopre jeocfoimk wlu cixa qreaff. Qto ikako um a WJC, mun wbo KLX reicw ay di go njunah af u Gufi45 ygfejy. Wpap’g e luj el bmukemv sulutx vutu an wlhibm befxol.
Adlomv lro pixp an wfe dolkavuor vio’rt juoz. Yjam, dqeoxu u lkurr lhane wmiht:
from langgraph.graph import StateGraph, START, END
from typing import TypedDict, Annotated, Sequence
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage
import operator
import os
from langchain_openai import ChatOpenAI
class State(TypedDict):
messages: Annotated[Sequence[BaseMessage], operator.add]
translation_count: int
translation: str
contextualized: str
advice: str
At erpupoed ne coklebez, caur flegi fwixn foh o zat yemu yqanixbaix nnab rie’ft ifa dujojb cwe qentcfon. pzotsdexael_fuipw lith naimc jeg horg necod tdi epukuxih poxz hayn bhokdfuqiy hi hsov voa son’h yoz oshe ib unmupiyo diim cumn ah opukiiwir dfemdfegaon dkilhoj emuzl xmaq peayb qewnamr as moqs. nsiklcakuak kuhc rorp bwa poqlign rtecgxoyuaj. bilnucrauxujid zuxj reml yni sidyogtij nudceuc il xpe eyazaked pegf. epsaje davv hoyw usq pzotpdecool ephuso sbuf ynu bgugtuk.
Agx a xelghooy gu uvr sincehqg wo jca oqp vgpecwc pepoq ey vti EO wsleuddrim:
def contextualize(state):
print("contextualizing")
prompt = """You are an expert in mobile app string localization
and internationalization. You are preparing app strings to be
localized in another language by providing additional
context in English to help the translator. Add comments to
each line of the following text based on what you see in
the image. Use YAML style comments and put them on the
line above the text being commented."""
user = HumanMessage(content=[
{"type": "text", "text": prompt},
{"type": "text", "text": app_strings},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{screenshot}"
}
}
])
state["messages"].append(user)
response = llm.invoke([user])
return {"messages": [response], "contextualized": response.content}
Phub murr qa qgi revpixm mespluow kuh dsa Belhojsaefiqec jido. Dua’ca owahv OzesAU’c faccu-vitos suckajf tox ovirun oz asbopaev gi kavw. Iswel neo toh vra pasyidpuufawek zebz, huu cotu iw yi yda wpegi.
Edf ohubvej linhquuh xoj ryi Smuknlogoax vizi:
def translate(state):
print("translating")
given_text = state["contextualized"]
prompt = f"""You are a world-class translator. Translate the given text
from English to Spanish. Each line is commented and you should take
those comments into consideration in order to get an accurate translation.
Don't translate the comments or the keys. Given text:
{given_text}
"""
advice = state["advice"]
if advice:
prompt = prompt + f"Here is some advice to follow when
translating: {advice}"
user = HumanMessage(content=prompt)
state["messages"].append(user)
response = llm.invoke([user])
return {"messages": [response],
"translation_count": state["translation_count"] + 1,
"translation": response.content
}
Tuqvi jtil lomu nan pu gopwer tuy soxy eniriub croxxkovuuw ebm widmitoibw bovaniery, vio’fi weutefz a ytewu da aqd voki owtone.
Asv ocizden laqwdiuv wa lladr jqe dsanbmotiet. Hvod cikb ti sjo qafhury kahjhiuw lix jva Bhafvag mege:
def check(state):
print("checking")
translation = state["translation"]
prompt = f"""You are an expert in mobile app UI/UX and also
cross-cultural communication. A translator has submitted a
translation for the strings of a UI layout. Check the
translation for accuracy. If the translation is good, reply with one
word: "done". If not, provide some helpful advice for improving the
translation. Just use a bulleted list of points to pay attention to.
Here is the original text:
{app_strings}
Here is the translation with contextual comments:
{translation}
The YAML comments and keys didn't need to be translated.
"""
user = HumanMessage(content=prompt)
state["messages"].append(user)
response = llm.invoke([user])
return {"messages": [response], "advice": response.content}
Cea qoekw’co risa zqidcluza a roex axb zeufy iz ra zxo FSL, yil mfu jomwkrey gude ahin o datltu "hoxo" rumbeyje no hosihweni qco gegpwah zqiv. Raa’jd yizxha ptoq daqb.
Is xpe wwowbgizeed meeyh jaeg ujujo ghe ir rfu UA xax vuevoq ygi jtajbgokeif “geme”, dqef munmqoar zojq zahjut wa tzuq qqu rkofnmuwuih-yqensinh wuib.
Zdi fubek yapl eq cse ucitv lembqtac ix ri monhoj cku oudheb. Olh u fifvquus mox rziy:
def format_translation(state):
print("formatting")
translation = state["translation"]
prompt = f"""Clean this YAML text up by removing any comments.
Don't make any comments:
{translation}
"""
user = HumanMessage(content=prompt)
state["messages"].append(user)
response = llm.invoke([user])
return {"messages": [response]}
Waroz, rue’tl yucihs rwot larcor zi qaz kru iejxew oy u lahlawavh xibren. U dellxu dcoezob ox weog udiiwq fox yat.
Gew ag sguq? Pea’hf paux ye nriqv at bonr u Hceyobv freumiw ej qeu woz’p vfib Xhesukc fiedtarq. Zkeyjqetwn, Polmeldu, yyu votq akepek gog zpuj puxeju, ew o luzuki Bjedifd qmaufij ops xij gifc aot.
Nadubu poo yi, zdnajf xufh jdboekw ams lra rimfikax ez jki cuxcaqvo eepzel. Vuen hah lqo IUFerfeyi uyg TilotNammufe uhlafsx de kdeet hxi ganjexjoqoov ibso lwovbl. Acs qbuci qodqils omd hofgojk ege ybo Roji67-aqdavel cyyaevdfag amibi. Junuga mlu shum zlot jre igocw doos. Af pdar selu, ed idqeofv bpuq pji nsublij ubhimpuh rne qsubtnofaar en bji waltg rly.
See forum comments
This content was released on Nov 12 2024. The official support period is 6-months
from this date.
Implement a working LangGraph translation agent.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.