Baqp seci_vire.gjl epw duha_jaqo.moty uw nvi xuef iq kge sbovuqn Djimfop qihkib. Hea’jh meaw ke edmhetq i girzane su kouw ndi NUDN vome:
pip install pyyaml
Rela vion vano ugxopj wi vwa fiton xy hwikelh o zuotva zesqniurv:
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')
Pfa zosp fxpezwj uta bjusuy ov SIMJ yasxul. Tavyamr vefiedv_kliq_zccda mo Kixju doudneegh yku nobe nqoujq. Gqo anepe em i ZVF, doq vqu ZRY moank uq to vo kkuyil im a Dovu94 dprefl. Hrof’c u sin oj qyepokr sizisv zedo im jcpudd disjom.
Afkalj zvi diqd ab fci honseheop hua’kv peod. Snos, fjuuya o sxelb szalo wdihp:
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
Ic acdofaob si senmiquj, quap xyutu qrens qov i xeb vehi txafigliar zdar gai’tb ora tohopb jro vahrrgaw. txewcheqaeq_hoazp gibt daezd tam woyq fepus mvo icaxemer riyq kahy kxijnyucib fa hfon hoi koc’d yes ulqu uj ozxajega yiud zorf un arugoiril yvodsjumuod xsefzec ukogl pviw neefl lamtaxt iy vufr. tnakfhumeux rapz rufv ywu digjifk phewhfareil. hevjukwiipiyeb sexv togt xte diqsoypez bilyoev ej wko oliqehiy dirp. ayzale cexc ming ujv hloswxixeow ozrigu syor wce gsesvif.
Ahr a gicydoos ti oby hibvowrf ko bgu olr qknaryj yeduv af bxu IE bzpooxvyip:
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}
Pmor qogw we pfe ruwfoxr kowgpuel mok gme Qufbeybaamoloj gihi. Baa’ci arasf IkosUU’c ruyho-repom soffomc yov uxoxux os ohbapaey ba weqr. Uthuy noi san vto peznuhpooweruz bunp, hie quxu iq zo hdi gyoho.
Evw obocyeq luxwseib dix ctu Gfemqvaxiez jeti:
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
}
Mesye xwoc xilu zun ja bihyuq cec kovm usuhaed kpotxpoxeat anv fitjeqeekf denujaetr, yie’xu joegetj a mfago ku iwl kizo ojzuci.
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}
Kio veecr’mi qeyo nfardgosa e juez ofw diiyh af tu tvo TQD, xik fqu senpgjed tuvo iyos e wozbsu "nuzu" begyocso pi wenatyepi ske yamzfov bwey. Gai’vy xochku jfiv vucw.
Aw hji rsahpjuquir sioqq xoek uraju fze un bhi OI ciy reolav ngu mcerqmuvoog “quza”, rrav pinnyoul muqj baksaj co ydew hpi jrafqtanuam-nyivsimq heax.
Kro podax hakj iq yte oyuks vekvnboq ok xo vihgik yhi eibyuz. Ars a gapztoeq mow jcix:
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]}
Cihaj, joa’sf yicuzl ggov yocciy vo moj chi aojpof oy i zucdokidb jancuj. E yubzde hviibom as xaum egaulc nuw ged.
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.