Author Topic: Storing and Displaying Translated Tags  (Read 259 times)

karbock

  • Sr. Member
  • ****
  • Posts: 320
Storing and Displaying Translated Tags


If you wish to store two versions of some tags (original + translated),
the method proposed here uses:
  • one custom tag to store all the translations,
  • virtual tags, one for each translated piece of information.

Example used throughout this post

Let us take as example a track and its translation/transliteration:

Original
Translated/Transliterated
Album ArtistЧАЙКОВСКИЙ, ПётрTCHAIKOVSKY, Piotr
AlbumComplete Piano Works (vol. 4)
ArtistПОСТНИКОВА, ВикторияPOSTNIKOVA, Viktoria
ComposerЧАЙКОВСКИЙ, ПётрTCHAIKOVSKY, Piotr
WorkВремена годаThe Seasons
Movement NameДекабрь: СвяткиDecember: Christmas
TitleВремена года - 12. Декабрь: СвяткиThe Seasons - 12. December: Christmas

Custom tag

One custom tag suffices to store all the translations if you follow simple syntactic conventions.

Custom tag: TranslatedTags

Conventions:
  • Each piece of information is in the form {TagName: Value} or {TagCode: Value}.
  • Semicolons ; are optional, but allow for a clearer display with the tag inspector.
With our example, TranslatedTags will contain:
Code
{Album Artist:TCHAIKOVSKY, Piotr}; {Artist:POSTNIKOVA, Viktoria}; {Composer:TCHAIKOVSKY, Piotr}; {Work:The Seasons}; {Movement Name:December: Christmas}; {Title:The Seasons - 12. December: Christmas}

NOTES:
  • If you already use { and } in your tags, choose other unique symbols.
  • While complete tag names are used here, two-letter codes could also do the trick: AA, AR, CO, WO, MO, TI.

Typical virtual tag formula

Virtual tag TranslatedArtist will display:
- the piece of information found in TranslatedTags within {Artist:} or {AR:} if it exists,
- Artist otherwise (inside an $IsNull declaration to prevent from displaying "Unknown Artist").

The matching formula is the following:
Code
$If(
    $IsMatch(<TranslatedTags>,"(?<={(Artist|AR)[:])[^}]*(?=})"),
    $RxMatch(<TranslatedTags>,"(?<={(Artist|AR)[:])[^}]*(?=})"),
    $IsNull(<Artist>,,<Artist>)
)
(Newlines and indentations have been added for the sake of readability.)

Comments:
  • [^}]* = a string containing no '}', possibly null
  • (?<={(Artist|AR)[:]) = the string must be preceded by '{Artist:' or '{AR:'
  • (?=}) = the string must be followed by '}'

Formulas for common tags

Just adapt the table to your needs:
- if you wish to use other separators;
- if you use other fields, such as Conductor, Lyricist, etc.

Virtual Tag
Formula
Result
TranslatedAlbumArtist$If($IsMatch(<TranslatedTags>,"(?<={(Album Artist|AA)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Album Artist|AA)[:])[^}]*(?=})"),$IsNull(<Album Artist>,,<Album Artist>))TCHAIKOVSKY, Piotr
TranslatedAlbum$If($IsMatch(<TranslatedTags>,"(?<={(Album|AL)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Album|AL)[:])[^}]*(?=})"),$IsNull(<Album>,,<Album>))
TranslatedArtist$If($IsMatch(<TranslatedTags>,"(?<={(Artist|AR)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Artist|AR)[:])[^}]*(?=})"),$IsNull(<Artist>,,<Artist>))POSTNIKOVA, Viktoria
TranslatedComposer$If($IsMatch(<TranslatedTags>,"(?<={(Composer|CO)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Composer|CO)[:])[^}]*(?=})"),$IsNull(<Composer>,,<Composer>))TCHAIKOVSKY, Piotr
TranslatedWork$If($IsMatch(<TranslatedTags>,"(?<={(Work|WO)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Work|WO)[:])[^}]*(?=})"),$IsNull(<Work>,,<Work>))The Seasons
TranslatedMovementName$If($IsMatch(<TranslatedTags>,"(?<={(Movement Name|MO)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Movement Name|MO)[:])[^}]*(?=})"),$IsNull(<Movement Name>,,<Movement Name>))December: Christmas
TranslatedTitle$If($IsMatch(<TranslatedTags>,"(?<={(Title|TI)[:])[^}]*(?=})"),$RxMatch(<TranslatedTags>,"(?<={(Title|TI)[:])[^}]*(?=})"),$IsNull(<Title>,,<Title>))The Seasons - 12. December: Christmas

References

MusicBee functions for virtual tags cheatsheet
Regular Expressions: coding, examples, testing resources
Last Edit: December 17, 2023, 04:35:27 PM by karbock