! *viewer/messagelib.pvc - Controls a Message Library Entry
! By Gord Davey
! (c) Copyright 2004-2005 Sage Software Canada Ltd.
! Version Info:
! Source Code File: $RCSfile: messagelib.pvs,v $   Version: $Revision: 1.5 $
!      Last Edited: $Date: 2005/10/14 15:31:18 $   Author: $Author: gordd $
!
! This object contains the logic to control Message Library entries
!
! new("*viewer/messagelib", MessageFileName$ )
! Each time a new message library is needed, this object may be used.
! It will add and remove message library entries, working out the
! language code needed based on simply rules.
!
! If using App Server, tries to set language to Client's Language
! If %LANG set, tries to set language to that language
! If env var PVXLANG set, tries to set language to that language
! If env var LAN set, tries to set language to that language
! else set to english.
!
! Languages are 2 character codes "en" for english etc.
! MessageFileName passed to this object must not include the file extension
! which represents the language (pass "filename" not "filename.en") as the
! language will be automatically appended. (in lowercase)
!
!
def class "*viewer/messagelib" create OnCreate required delete OnDelete required

    property Version$ = mid(mid("$Revision: 1.5 $",12), 1, len(mid("$Revision: 1.5 $",12)) - 2)

    local This, IsSet, FileName$

    property Language$                      set err
    property File$ = FileName$ + Language$  set err

    function Language(Language$)
        enter (Value$)
        return This'SetMessageLibrary(Value$)

    function local SetMessageLibrary(Language$)
        enter (Value$)

        if mid(Value$,1,1) = "." \
            then Value$ = lcs(Value$(2))

        messagelib add FileName$ + Value$, err=NoSuchMessageLibrary
        This'DropMessageLibrary()
        Language$ = Value$
        IsSet = 1
        return 1

        NoSuchMessageLibrary:
        return 0

    function local DropMessageLibrary()
        if IsSet \
            then messagelib drop FileName$ + Language$, err=*next; return 1
        return 0

fnend
!
!
! new("*viewer/messagelib", MessageFileName$ )
OnCreate:
    This = _obj

    enter (Value$), err=InvalidEnter

    if Value$ = "" \
        then exit 17

    if mid(Value$,-1) <> "." \
        then Value$ += "."

    if %APS and %APS'SessionID$ > "" \
        then Language$ = lcs(%APS'ClientLang$)
    messagelib add Value$ + Language$, err=*next; goto OC_MessLibSet

    if mid(%Lang$,1,1) = "." \
        then Language$ = lcs(%Lang$(2)) \
        else Language$ = lcs(%Lang$)
    messagelib add Value$ + Language$, err=*next; goto OC_MessLibSet

    Language$ = lcs(env("PVXLANG"))
    if mid(Language$,1,1) = "." \
        then Language$ = lcs(Language$(2))
    messagelib add Value$ + Language$, err=*next; goto OC_MessLibSet

    Language$ = lcs(env("LANG"))
    if mid(Language$,1,1) = "." \
        then Language$ = lcs(Language$(2))
    messagelib add Value$ + Language$, err=*next; goto OC_MessLibSet

    Language$ = "en"
    messagelib add Value$ + Language$, err=*next; goto OC_MessLibSet

    exit 12

    InvalidEnter:
        exit 36
!
    OC_MessLibSet:
        IsSet = 1
        FileName$ = Value$
        return
!
!
OnDelete:
    This'DropMessageLibrary()
    return
