-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from wadeking98/feat-lear-entries
added initial lear database entries
- Loading branch information
Showing
8 changed files
with
206 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { DirectiveFunction } from "vue"; | ||
import { DirectiveBinding } from "vue/types/options"; | ||
import VueI18n from "." | ||
|
||
export const translate: DirectiveFunction = (el: Element, binding: DirectiveBinding) => { | ||
el.textContent = $translate(binding.value) | ||
} | ||
|
||
// Uses the entity_type as well as the registration description to lookup translations for entries from the LEAR database | ||
export const $translate = (value: string): string => { | ||
const messages = VueI18n.messages | ||
const locale = VueI18n.locale | ||
const bindingValues = value.split(".") | ||
let transReturn | ||
// try old translation first | ||
if (bindingValues.length >= 2) { | ||
const translationAttempt = (messages[locale][bindingValues[0]] as { [key: string]: string | any })?.[bindingValues[1]] | ||
if (typeof (translationAttempt) === "string") { | ||
transReturn = translationAttempt | ||
} else { | ||
// we know we're working with an entity from LEAR | ||
const description = translationAttempt?.displayName ?? translationAttempt?.title | ||
if (typeof (description) === "string") { | ||
transReturn = description | ||
} else if (typeof (description) !== "undefined") { | ||
// we are working with a description object, indexed by entity type: BC, SP, etc. | ||
if (bindingValues.length >= 3) { | ||
// if entity type is passed in as a binding value | ||
transReturn = description[bindingValues[2]] | ||
} else { | ||
transReturn = translationAttempt?.title | ||
} | ||
} | ||
} | ||
} | ||
return transReturn ?? value | ||
} |
Oops, something went wrong.