Add creating and basic editing of translation
This commit is contained in:
25
lib/outlook/translations/basic.ex
Normal file
25
lib/outlook/translations/basic.ex
Normal file
@ -0,0 +1,25 @@
|
||||
defmodule Outlook.Translations.Basic do
|
||||
|
||||
alias Outlook.InternalTree.InternalNode
|
||||
alias Outlook.InternalTree.TranslationUnit
|
||||
|
||||
def internal_tree_to_tunit_map(tree) do
|
||||
collect_translation_units(tree)
|
||||
|> Enum.map(fn tunit -> {tunit.uuid, tunit} end)
|
||||
|> Enum.into(%{})
|
||||
end
|
||||
|
||||
defp collect_translation_units([%InternalNode{type: :element} = node | rest]) do
|
||||
collect_translation_units(node.content) ++ collect_translation_units(rest)
|
||||
end
|
||||
|
||||
defp collect_translation_units([%TranslationUnit{} = tunit | rest]) do
|
||||
[tunit | collect_translation_units(rest)]
|
||||
end
|
||||
|
||||
defp collect_translation_units([_|rest]) do
|
||||
[] ++ collect_translation_units(rest)
|
||||
end
|
||||
|
||||
defp collect_translation_units([]), do: []
|
||||
end
|
||||
Reference in New Issue
Block a user