Skip to content

Commit

Permalink
feat: log missing translation instead of panic
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlin1228 committed Oct 11, 2024
1 parent 735ee2c commit 06cc895
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
20 changes: 12 additions & 8 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,18 @@ impl Project {
symbol_name,
))?;
for key in i18n_keys.iter() {
let translation =
self.project
.get_translation(&self.db.conn, key)
.context(format!(
"try to add translation for symbol {}, but translation {} doesn't exist",
symbol_name, key
))?;
models::TranslationUsage::create(&self.db.conn, &translation, &symbol)?;
match self.project.get_translation(&self.db.conn, key) {
Ok(translation) => {
models::TranslationUsage::create(&self.db.conn, &translation, &symbol)
.context(format!(
"relate symbol {} to translation {}",
symbol_name, key
))?;
}
Err(_) => {
println!("try to add translation for symbol {}, but translation {} doesn't exist", symbol_name, key);
}
}
}
}
Ok(())
Expand Down
15 changes: 7 additions & 8 deletions web/src/search/components/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ const StyledTreeView = styled(SimpleTreeView)({
});

const mapAllModuleSymbolToString = (
project_root: string,
tracePaths: ModuleSymbol[][]
): string[][] => {
return tracePaths.map((tracePath) =>
tracePath.map(({ module_path, symbol_name }) => {
let shorterPath = module_path.slice(project_root.length);
return `${symbol_name}@${shorterPath}`;
if (module_path.startsWith("/")) {
return `${symbol_name}@${module_path.slice(1)}`;
} else {
return `${symbol_name}@${module_path}`;
}
})
);
};
Expand Down Expand Up @@ -86,7 +88,7 @@ export const TreeView = React.memo(function TreeView({
return (
<Box
sx={{
"overflow-x": "scroll",
overflowX: "scroll",
pb: 2,
}}
>
Expand All @@ -103,10 +105,7 @@ export const TreeView = React.memo(function TreeView({
{Object.entries(traceTargets).map(([traceTarget, paths]) => (
<TracePathToTreeView
key={`${i18nKey} - ${url} - ${traceTarget}`}
tracePaths={mapAllModuleSymbolToString(
data.project_root,
paths
)}
tracePaths={mapAllModuleSymbolToString(paths)}
/>
))}
</TreeItem>
Expand Down

0 comments on commit 06cc895

Please sign in to comment.