From fcd9792198647f911c469673105b6a838f5bdc67 Mon Sep 17 00:00:00 2001 From: r-cemper Date: Tue, 21 May 2024 16:39:17 +0200 Subject: [PATCH] add Docker --- .dockerignore | 3 + .gitattributes | 11 + .github/workflows/objectscript-quality.yml | 12 + .github/workflows_build-push-gcr.yaml | 19 + .github/workflows_bump-module-version.yml | 28 + .github/workflows_github-registry.yml | 25 + .github/workflows_runtests.yml | 28 + .gitignore | 5 + .vscode/extensions.json | 17 + .vscode/launch.json | 18 + .vscode/settings.json | 22 + Dockerfile | 1 + .../NumberTranslate/Initialize.cls | 470 ++++++------ .../NumberTranslate/NumberTranslate.cls | 706 +++++++++--------- README.md | 33 + ascript.sh | 4 + demo.script | 17 + dev.md | 117 +++ docker-compose.yml | 12 + iris.script | 17 + 20 files changed, 977 insertions(+), 588 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitattributes create mode 100644 .github/workflows/objectscript-quality.yml create mode 100644 .github/workflows_build-push-gcr.yaml create mode 100644 .github/workflows_bump-module-version.yml create mode 100644 .github/workflows_github-registry.yml create mode 100644 .github/workflows_runtests.yml create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 Dockerfile create mode 100644 ascript.sh create mode 100644 demo.script create mode 100644 dev.md create mode 100644 docker-compose.yml create mode 100644 iris.script diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..114a057 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/.DS_Store +iris-main.log +.git \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..43e39d5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +*.cls linguist-language=ObjectScript +*.mac linguist-language=ObjectScript +*.int linguist-language=ObjectScript +*.inc linguist-language=ObjectScript +*.csp linguist-language=Html + +*.sh text eol=lf +*.cls text eol=lf +*.mac text eol=lf +*.int text eol=lf +Dockerfil* text eol=lf diff --git a/.github/workflows/objectscript-quality.yml b/.github/workflows/objectscript-quality.yml new file mode 100644 index 0000000..df27ddf --- /dev/null +++ b/.github/workflows/objectscript-quality.yml @@ -0,0 +1,12 @@ +name: objectscriptquality +on: push + +jobs: + linux: + name: Linux build + runs-on: ubuntu-latest + + steps: + - name: Execute ObjectScript Quality Analysis + run: wget https://raw.githubusercontent.com/litesolutions/objectscriptquality-jenkins-integration/master/iris-community-hook.sh && sh ./iris-community-hook.sh + diff --git a/.github/workflows_build-push-gcr.yaml b/.github/workflows_build-push-gcr.yaml new file mode 100644 index 0000000..4272bce --- /dev/null +++ b/.github/workflows_build-push-gcr.yaml @@ -0,0 +1,19 @@ +name: Cloud Run Deploy + +on: + push: + branches: + - master + - main + workflow_dispatch: + +jobs: + deploy: + uses: intersystems-community/demo-deployment/.github/workflows/deployment.yml@master + with: + # Replace the name: parameter below to have your application deployed at + # https://project-name.demo.community.intersystems.com/ + name: project-name + secrets: + # Do not forget to add Secret in GitHub Repoository Settings with name SERVICE_ACCOUNT_KEY + SERVICE_ACCOUNT_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }} diff --git a/.github/workflows_bump-module-version.yml b/.github/workflows_bump-module-version.yml new file mode 100644 index 0000000..7c54977 --- /dev/null +++ b/.github/workflows_bump-module-version.yml @@ -0,0 +1,28 @@ +name: versionbump + +on: + push: + branches: + - master + - main + release: + types: + - released +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Bump version + run: | + git config --global user.name 'ProjectBot' + git config --global user.email 'bot@users.noreply.github.com' + VERSION=$(sed -n '0,/.*\(.*\)<\/Version>.*/s//\1/p' module.xml) + VERSION=`echo $VERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.` + sed -i "0,/\(.*\)<\/Version>/s//$VERSION<\/Version>/" module.xml + git add module.xml + git commit -m 'auto bump version' + git push diff --git a/.github/workflows_github-registry.yml b/.github/workflows_github-registry.yml new file mode 100644 index 0000000..05642f6 --- /dev/null +++ b/.github/workflows_github-registry.yml @@ -0,0 +1,25 @@ +name: Build and publish a Docker image to ghcr.io +on: + + # publish on pushes to the main branch (image tagged as "latest") + # image name: will be: ghcr.io/${{ github.repository }}:latest + # e.g.: ghcr.io/intersystems-community/intersystems-iris-dev-template:latest + push: + branches: + - master + +jobs: + docker_publish: + runs-on: "ubuntu-20.04" + + steps: + - uses: actions/checkout@v2 + + # https://github.com/marketplace/actions/push-to-ghcr + - name: Build and publish a Docker image for ${{ github.repository }} + uses: macbre/push-to-ghcr@master + with: + image_name: ${{ github.repository }} + github_token: ${{ secrets.GITHUB_TOKEN }} + # optionally push to the Docker Hub (docker.io) + # docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }} # see https://hub.docker.com/settings/security diff --git a/.github/workflows_runtests.yml b/.github/workflows_runtests.yml new file mode 100644 index 0000000..b5e564f --- /dev/null +++ b/.github/workflows_runtests.yml @@ -0,0 +1,28 @@ +name: unittest + +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + release: + types: + - released + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and Test + uses: docker/build-push-action@v2 + with: + context: . + push: false + load: true + tags: ${{ github.repository }}:${{ github.sha }} + build-args: TESTS=1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..258bec2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +iris-main.log +.env +.git + diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..a019fe9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,17 @@ +{ + "recommendations": [ + "eamodio.gitlens", + "georgejames.gjlocate", + "github.copilot", + "intersystems-community.servermanager", + "intersystems-community.sqltools-intersystems-driver", + "intersystems-community.testingmanager", + "intersystems-community.vscode-objectscript", + "intersystems.language-server", + "mohsen1.prettify-json", + "ms-azuretools.vscode-docker", + "ms-python.python", + "ms-python.vscode-pylance", + "ms-vscode-remote.remote-containers" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c17f3ea --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "objectscript", + "request": "launch", + "name": "ObjectScript Debug Class", + "program": "##class(dc.sample.ObjectScript).Test()", + }, + { + "type": "objectscript", + "request": "attach", + "name": "ObjectScript Attach", + "processId": "${command:PickProcess}", + "system": true + } + ] + } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..044a229 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "files.associations": { + + "Dockerfile*": "dockerfile", + "iris.script": "objectscript" + }, + "objectscript.conn" :{ + "active": true, + "ns": "USER", + "username": "_SYSTEM", + "password": "SYS", + "docker-compose": { + "service": "iris", + "internalPort": 52773 + }, + "links": { + "UnitTest Portal": "${serverUrl}/csp/sys/%25UnitTest.Portal.Home.cls?$NAMESPACE=IRISAPP" + } + }, + "intersystems.testingManager.client.relativeTestRoot": "tests" + +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..13acaa3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +# fake for OEX docker detection diff --git a/NumberTranslate/NumberTranslate/Initialize.cls b/NumberTranslate/NumberTranslate/Initialize.cls index 472f8ad..44f4ad2 100644 --- a/NumberTranslate/NumberTranslate/Initialize.cls +++ b/NumberTranslate/NumberTranslate/Initialize.cls @@ -1,235 +1,235 @@ -/// Initialize Global with number translate -Class NumberTranslate.Initialize Extends %RegisteredObject -{ - -ClassMethod Initialize() -{ - kill ^NumberTranslate - - // Create the global variable with texto according to lang and number - set ^NumberTranslate("Config")=1 - set ^NumberTranslate("Config","lang")="es;ca;en;ru" - - set ^NumberTranslate("Config","lang","es","billions")="billones" - set ^NumberTranslate("Config","lang","es","billion")="billón" - set ^NumberTranslate("Config","lang","es","million")="millón" - set ^NumberTranslate("Config","lang","es","millions")="millones" - set ^NumberTranslate("Config","lang","es","trillion")="trillón" - set ^NumberTranslate("Config","lang","es","trillions")="trillones" - set ^NumberTranslate("Config","lang","es","thousand")="mil" - set ^NumberTranslate("Config","lang","es","hundred")="cien" - set ^NumberTranslate("Config","lang","es","unit")="un" - set ^NumberTranslate("Config","lang","es","concat-tens")=" y " - set ^NumberTranslate("Config","lang","es","concat-cents")=" " - - set ^NumberTranslate("Config","lang","ca","billion")="bilió" - set ^NumberTranslate("Config","lang","ca","billions")="bilions" - set ^NumberTranslate("Config","lang","ca","million")="milió" - set ^NumberTranslate("Config","lang","ca","millions")="milions" - set ^NumberTranslate("Config","lang","ca","trillion")="trilló" - set ^NumberTranslate("Config","lang","ca","trillions")="trillons" - set ^NumberTranslate("Config","lang","ca","thousand")="mil" - set ^NumberTranslate("Config","lang","ca","hundred")="cent" - set ^NumberTranslate("Config","lang","ca","unit")="un" - set ^NumberTranslate("Config","lang","ca","concat-tens")="-" - set ^NumberTranslate("Config","lang","ca","concat-cents")=" " - - set ^NumberTranslate("Config","lang","en","billion")="billion" - set ^NumberTranslate("Config","lang","en","billions")="billions" - set ^NumberTranslate("Config","lang","en","million")="million" - set ^NumberTranslate("Config","lang","en","millions")="millions" - set ^NumberTranslate("Config","lang","en","trillion")="trillion" - set ^NumberTranslate("Config","lang","en","trillions")="trillions" - set ^NumberTranslate("Config","lang","en","thousand")="thousand" - set ^NumberTranslate("Config","lang","en","hundred")="hundred" - set ^NumberTranslate("Config","lang","en","unit")="one" - set ^NumberTranslate("Config","lang","en","concat-tens")="-" - set ^NumberTranslate("Config","lang","en","concat-cents")=" and " - - set ^NumberTranslate("Config","lang","ru","billion")="billion" - set ^NumberTranslate("Config","lang","ru","billions")="billions" - set ^NumberTranslate("Config","lang","ru","million")="миллион" - set ^NumberTranslate("Config","lang","ru","millions")="millions" - set ^NumberTranslate("Config","lang","ru","trillion")="trillion" - set ^NumberTranslate("Config","lang","ru","trillions")="trillions" - set ^NumberTranslate("Config","lang","ru","thousand")="тысяч" - set ^NumberTranslate("Config","lang","ru","hundred")="Сто" - set ^NumberTranslate("Config","lang","ru","unit")="Одна" - set ^NumberTranslate("Config","lang","ru","concat-tens")=" " - set ^NumberTranslate("Config","lang","ru","concat-cents")=" " - - set ^NumberTranslate("Current","lang")="en" - set ^NumberTranslate("Current","culture")="" - set ^NumberTranslate("Current","debug")=0 - - // Number definition - // units and tens (es) - set ^NumberTranslate("Config","lang","es","unit",1)="uno" - set ^NumberTranslate("Config","lang","es","unit",2)="dos" - set ^NumberTranslate("Config","lang","es","unit",3)="tres" - set ^NumberTranslate("Config","lang","es","unit",4)="cuatro" - set ^NumberTranslate("Config","lang","es","unit",5)="cinco" - set ^NumberTranslate("Config","lang","es","unit",6)="seis" - set ^NumberTranslate("Config","lang","es","unit",7)="siete" - set ^NumberTranslate("Config","lang","es","unit",8)="ocho" - set ^NumberTranslate("Config","lang","es","unit",9)="nueve" - set ^NumberTranslate("Config","lang","es","unit",10)="diez" - set ^NumberTranslate("Config","lang","es","unit",11)="once" - set ^NumberTranslate("Config","lang","es","unit",12)="doce" - set ^NumberTranslate("Config","lang","es","unit",13)="trece" - set ^NumberTranslate("Config","lang","es","unit",14)="catorce" - set ^NumberTranslate("Config","lang","es","unit",15)="quince" - set ^NumberTranslate("Config","lang","es","unit",16)="dieciseis" - set ^NumberTranslate("Config","lang","es","unit",17)="diecisiete" - set ^NumberTranslate("Config","lang","es","unit",18)="dieciocho" - set ^NumberTranslate("Config","lang","es","unit",19)="diecinueve" - set ^NumberTranslate("Config","lang","es","unit",20)="veinti" - set ^NumberTranslate("Config","lang","es","unit",21)="treinta" - set ^NumberTranslate("Config","lang","es","unit",22)="cuarenta" - set ^NumberTranslate("Config","lang","es","unit",23)="cincuenta" - set ^NumberTranslate("Config","lang","es","unit",24)="sesenta" - set ^NumberTranslate("Config","lang","es","unit",25)="setenta" - set ^NumberTranslate("Config","lang","es","unit",26)="ochenta" - set ^NumberTranslate("Config","lang","es","unit",27)="noventa" - set ^NumberTranslate("Config","lang","es","unit",29)="veinte" - - // units and tens (ca) - set ^NumberTranslate("Config","lang","ca","unit",1)="u" - set ^NumberTranslate("Config","lang","ca","unit",2)="dos" - set ^NumberTranslate("Config","lang","ca","unit",3)="tres" - set ^NumberTranslate("Config","lang","ca","unit",4)="quatre" - set ^NumberTranslate("Config","lang","ca","unit",5)="cinc" - set ^NumberTranslate("Config","lang","ca","unit",6)="sis" - set ^NumberTranslate("Config","lang","ca","unit",7)="set" - set ^NumberTranslate("Config","lang","ca","unit",8)="vuit" - set ^NumberTranslate("Config","lang","ca","unit",9)="nou" - set ^NumberTranslate("Config","lang","ca","unit",10)="deu" - set ^NumberTranslate("Config","lang","ca","unit",11)="onze" - set ^NumberTranslate("Config","lang","ca","unit",12)="dotze" - set ^NumberTranslate("Config","lang","ca","unit",13)="tretze" - set ^NumberTranslate("Config","lang","ca","unit",14)="catorze" - set ^NumberTranslate("Config","lang","ca","unit",15)="quinze" - set ^NumberTranslate("Config","lang","ca","unit",16)="setze" - set ^NumberTranslate("Config","lang","ca","unit",17)="disset" - set ^NumberTranslate("Config","lang","ca","unit",18)="divuit" - set ^NumberTranslate("Config","lang","ca","unit",19)="dinou" - set ^NumberTranslate("Config","lang","ca","unit",20)="vint-i" - set ^NumberTranslate("Config","lang","ca","unit",21)="trenta" - set ^NumberTranslate("Config","lang","ca","unit",22)="quaranta" - set ^NumberTranslate("Config","lang","ca","unit",23)="cinquanta" - set ^NumberTranslate("Config","lang","ca","unit",24)="seixanta" - set ^NumberTranslate("Config","lang","ca","unit",25)="setanta" - set ^NumberTranslate("Config","lang","ca","unit",26)="vuitanta" - set ^NumberTranslate("Config","lang","ca","unit",27)="noranta" - set ^NumberTranslate("Config","lang","ca","unit",29)="vint" - - // units and tens (en) - set ^NumberTranslate("Config","lang","en","unit",1)="one" - set ^NumberTranslate("Config","lang","en","unit",2)="two" - set ^NumberTranslate("Config","lang","en","unit",3)="three" - set ^NumberTranslate("Config","lang","en","unit",4)="four" - set ^NumberTranslate("Config","lang","en","unit",5)="five" - set ^NumberTranslate("Config","lang","en","unit",6)="six" - set ^NumberTranslate("Config","lang","en","unit",7)="seven" - set ^NumberTranslate("Config","lang","en","unit",8)="eight" - set ^NumberTranslate("Config","lang","en","unit",9)="nine" - set ^NumberTranslate("Config","lang","en","unit",10)="ten" - set ^NumberTranslate("Config","lang","en","unit",11)="eleven" - set ^NumberTranslate("Config","lang","en","unit",12)="twelve" - set ^NumberTranslate("Config","lang","en","unit",13)="thirteen" - set ^NumberTranslate("Config","lang","en","unit",14)="fourteen" - set ^NumberTranslate("Config","lang","en","unit",15)="fiveteen" - set ^NumberTranslate("Config","lang","en","unit",16)="sixteen" - set ^NumberTranslate("Config","lang","en","unit",17)="seventeen" - set ^NumberTranslate("Config","lang","en","unit",18)="eighteen" - set ^NumberTranslate("Config","lang","en","unit",19)="nineteen" - set ^NumberTranslate("Config","lang","en","unit",20)="twenty" - set ^NumberTranslate("Config","lang","en","unit",21)="thirty" - set ^NumberTranslate("Config","lang","en","unit",22)="forty" - set ^NumberTranslate("Config","lang","en","unit",23)="fifty" - set ^NumberTranslate("Config","lang","en","unit",24)="sixty" - set ^NumberTranslate("Config","lang","en","unit",25)="seventy" - set ^NumberTranslate("Config","lang","en","unit",26)="eighty" - set ^NumberTranslate("Config","lang","en","unit",27)="ninety" - set ^NumberTranslate("Config","lang","en","unit",29)="twenty" - - // units and tens (ru) - set ^NumberTranslate("Config","lang","ru","unit",1)="один" - set ^NumberTranslate("Config","lang","ru","unit",2)="два" - set ^NumberTranslate("Config","lang","ru","unit",3)="три" - set ^NumberTranslate("Config","lang","ru","unit",4)="четыре" - set ^NumberTranslate("Config","lang","ru","unit",5)="пять" - set ^NumberTranslate("Config","lang","ru","unit",6)="шесть" - set ^NumberTranslate("Config","lang","ru","unit",7)="семь" - set ^NumberTranslate("Config","lang","ru","unit",8)="восемь" - set ^NumberTranslate("Config","lang","ru","unit",9)="девять" - set ^NumberTranslate("Config","lang","ru","unit",10)="десять" - set ^NumberTranslate("Config","lang","ru","unit",11)="одиннадцать" - set ^NumberTranslate("Config","lang","ru","unit",12)="двенадцать" - set ^NumberTranslate("Config","lang","ru","unit",13)="тринадцать" - set ^NumberTranslate("Config","lang","ru","unit",14)="четырнадцать" - set ^NumberTranslate("Config","lang","ru","unit",15)="пятнадцать" - set ^NumberTranslate("Config","lang","ru","unit",16)="шестнадцать" - set ^NumberTranslate("Config","lang","ru","unit",17)="семнадцать" - set ^NumberTranslate("Config","lang","ru","unit",18)="восемнадцать" - set ^NumberTranslate("Config","lang","ru","unit",19)="девятнадцать" - set ^NumberTranslate("Config","lang","ru","unit",20)="двадцать" - set ^NumberTranslate("Config","lang","ru","unit",21)="тридцать" - set ^NumberTranslate("Config","lang","ru","unit",22)="сорок" - set ^NumberTranslate("Config","lang","ru","unit",23)="пятьдесят" - set ^NumberTranslate("Config","lang","ru","unit",24)="шестьдесят" - set ^NumberTranslate("Config","lang","ru","unit",25)="семьдесят" - set ^NumberTranslate("Config","lang","ru","unit",26)="восемьдесят" - set ^NumberTranslate("Config","lang","ru","unit",27)="девяносто" - set ^NumberTranslate("Config","lang","ru","unit",29)="двадцать" - - // Hundreds (es) - set ^NumberTranslate("Config","lang","es","hundred",0)="cien" - set ^NumberTranslate("Config","lang","es","hundred",1)="ciento" - set ^NumberTranslate("Config","lang","es","hundred",2)="doscientos" - set ^NumberTranslate("Config","lang","es","hundred",3)="trescientos" - set ^NumberTranslate("Config","lang","es","hundred",4)="cuatrocientos" - set ^NumberTranslate("Config","lang","es","hundred",5)="quinientos" - set ^NumberTranslate("Config","lang","es","hundred",6)="seiscientos" - set ^NumberTranslate("Config","lang","es","hundred",7)="setecientos" - set ^NumberTranslate("Config","lang","es","hundred",8)="ochocientos" - set ^NumberTranslate("Config","lang","es","hundred",9)="novecientos" - - // Hundreds (ca) - set ^NumberTranslate("Config","lang","ca","hundred",0)="cent" - set ^NumberTranslate("Config","lang","ca","hundred",1)="cent" - set ^NumberTranslate("Config","lang","ca","hundred",2)="dos-cents" - set ^NumberTranslate("Config","lang","ca","hundred",3)="tres-cents" - set ^NumberTranslate("Config","lang","ca","hundred",4)="quatre-cents" - set ^NumberTranslate("Config","lang","ca","hundred",5)="cinc-cents" - set ^NumberTranslate("Config","lang","ca","hundred",6)="sis-cents" - set ^NumberTranslate("Config","lang","ca","hundred",7)="set-cents" - set ^NumberTranslate("Config","lang","ca","hundred",8)="vuit-cents" - set ^NumberTranslate("Config","lang","ca","hundred",9)="nou-cents" - - // Hundreds (en) - set ^NumberTranslate("Config","lang","en","hundred",0)="one hundred" - set ^NumberTranslate("Config","lang","en","hundred",1)="one hundred" - set ^NumberTranslate("Config","lang","en","hundred",2)="two hundred" - set ^NumberTranslate("Config","lang","en","hundred",3)="three hundred" - set ^NumberTranslate("Config","lang","en","hundred",4)="four hundred" - set ^NumberTranslate("Config","lang","en","hundred",5)="five hundred" - set ^NumberTranslate("Config","lang","en","hundred",6)="six hundred" - set ^NumberTranslate("Config","lang","en","hundred",7)="seven hundred" - set ^NumberTranslate("Config","lang","en","hundred",8)="eight hundred" - set ^NumberTranslate("Config","lang","en","hundred",9)="nine hundred" - - // Hundreds (ru) - set ^NumberTranslate("Config","lang","ru","hundred",0)="Сто" - set ^NumberTranslate("Config","lang","ru","hundred",1)="Сто" - set ^NumberTranslate("Config","lang","ru","hundred",2)="двести" - set ^NumberTranslate("Config","lang","ru","hundred",3)="триста" - set ^NumberTranslate("Config","lang","ru","hundred",4)="четыреста" - set ^NumberTranslate("Config","lang","ru","hundred",5)="пятьсот" - set ^NumberTranslate("Config","lang","ru","hundred",6)="шестьсот" - set ^NumberTranslate("Config","lang","ru","hundred",7)="семьсот" - set ^NumberTranslate("Config","lang","ru","hundred",8)="восемьсот" - set ^NumberTranslate("Config","lang","ru","hundred",9)="девятьсот" -} - -} +/// Initialize Global with number translate +Class NumberTranslate.Initialize Extends %RegisteredObject +{ + +ClassMethod Initialize() +{ + kill ^NumberTranslate + + // Create the global variable with texto according to lang and number + set ^NumberTranslate("Config")=1 + set ^NumberTranslate("Config","lang")="es;ca;en;ru" + + set ^NumberTranslate("Config","lang","es","billions")="billones" + set ^NumberTranslate("Config","lang","es","billion")="billón" + set ^NumberTranslate("Config","lang","es","million")="millón" + set ^NumberTranslate("Config","lang","es","millions")="millones" + set ^NumberTranslate("Config","lang","es","trillion")="trillón" + set ^NumberTranslate("Config","lang","es","trillions")="trillones" + set ^NumberTranslate("Config","lang","es","thousand")="mil" + set ^NumberTranslate("Config","lang","es","hundred")="cien" + set ^NumberTranslate("Config","lang","es","unit")="un" + set ^NumberTranslate("Config","lang","es","concat-tens")=" y " + set ^NumberTranslate("Config","lang","es","concat-cents")=" " + + set ^NumberTranslate("Config","lang","ca","billion")="bilió" + set ^NumberTranslate("Config","lang","ca","billions")="bilions" + set ^NumberTranslate("Config","lang","ca","million")="milió" + set ^NumberTranslate("Config","lang","ca","millions")="milions" + set ^NumberTranslate("Config","lang","ca","trillion")="trilló" + set ^NumberTranslate("Config","lang","ca","trillions")="trillons" + set ^NumberTranslate("Config","lang","ca","thousand")="mil" + set ^NumberTranslate("Config","lang","ca","hundred")="cent" + set ^NumberTranslate("Config","lang","ca","unit")="un" + set ^NumberTranslate("Config","lang","ca","concat-tens")="-" + set ^NumberTranslate("Config","lang","ca","concat-cents")=" " + + set ^NumberTranslate("Config","lang","en","billion")="billion" + set ^NumberTranslate("Config","lang","en","billions")="billions" + set ^NumberTranslate("Config","lang","en","million")="million" + set ^NumberTranslate("Config","lang","en","millions")="millions" + set ^NumberTranslate("Config","lang","en","trillion")="trillion" + set ^NumberTranslate("Config","lang","en","trillions")="trillions" + set ^NumberTranslate("Config","lang","en","thousand")="thousand" + set ^NumberTranslate("Config","lang","en","hundred")="hundred" + set ^NumberTranslate("Config","lang","en","unit")="one" + set ^NumberTranslate("Config","lang","en","concat-tens")="-" + set ^NumberTranslate("Config","lang","en","concat-cents")=" and " + + set ^NumberTranslate("Config","lang","ru","billion")="billion" + set ^NumberTranslate("Config","lang","ru","billions")="billions" + set ^NumberTranslate("Config","lang","ru","million")="миллион" + set ^NumberTranslate("Config","lang","ru","millions")="millions" + set ^NumberTranslate("Config","lang","ru","trillion")="trillion" + set ^NumberTranslate("Config","lang","ru","trillions")="trillions" + set ^NumberTranslate("Config","lang","ru","thousand")="тысяч" + set ^NumberTranslate("Config","lang","ru","hundred")="Сто" + set ^NumberTranslate("Config","lang","ru","unit")="Одна" + set ^NumberTranslate("Config","lang","ru","concat-tens")=" " + set ^NumberTranslate("Config","lang","ru","concat-cents")=" " + + set ^NumberTranslate("Current","lang")="en" + set ^NumberTranslate("Current","culture")="" + set ^NumberTranslate("Current","debug")=0 + + // Number definition + // units and tens (es) + set ^NumberTranslate("Config","lang","es","unit",1)="uno" + set ^NumberTranslate("Config","lang","es","unit",2)="dos" + set ^NumberTranslate("Config","lang","es","unit",3)="tres" + set ^NumberTranslate("Config","lang","es","unit",4)="cuatro" + set ^NumberTranslate("Config","lang","es","unit",5)="cinco" + set ^NumberTranslate("Config","lang","es","unit",6)="seis" + set ^NumberTranslate("Config","lang","es","unit",7)="siete" + set ^NumberTranslate("Config","lang","es","unit",8)="ocho" + set ^NumberTranslate("Config","lang","es","unit",9)="nueve" + set ^NumberTranslate("Config","lang","es","unit",10)="diez" + set ^NumberTranslate("Config","lang","es","unit",11)="once" + set ^NumberTranslate("Config","lang","es","unit",12)="doce" + set ^NumberTranslate("Config","lang","es","unit",13)="trece" + set ^NumberTranslate("Config","lang","es","unit",14)="catorce" + set ^NumberTranslate("Config","lang","es","unit",15)="quince" + set ^NumberTranslate("Config","lang","es","unit",16)="dieciseis" + set ^NumberTranslate("Config","lang","es","unit",17)="diecisiete" + set ^NumberTranslate("Config","lang","es","unit",18)="dieciocho" + set ^NumberTranslate("Config","lang","es","unit",19)="diecinueve" + set ^NumberTranslate("Config","lang","es","unit",20)="veinti" + set ^NumberTranslate("Config","lang","es","unit",21)="treinta" + set ^NumberTranslate("Config","lang","es","unit",22)="cuarenta" + set ^NumberTranslate("Config","lang","es","unit",23)="cincuenta" + set ^NumberTranslate("Config","lang","es","unit",24)="sesenta" + set ^NumberTranslate("Config","lang","es","unit",25)="setenta" + set ^NumberTranslate("Config","lang","es","unit",26)="ochenta" + set ^NumberTranslate("Config","lang","es","unit",27)="noventa" + set ^NumberTranslate("Config","lang","es","unit",29)="veinte" + + // units and tens (ca) + set ^NumberTranslate("Config","lang","ca","unit",1)="u" + set ^NumberTranslate("Config","lang","ca","unit",2)="dos" + set ^NumberTranslate("Config","lang","ca","unit",3)="tres" + set ^NumberTranslate("Config","lang","ca","unit",4)="quatre" + set ^NumberTranslate("Config","lang","ca","unit",5)="cinc" + set ^NumberTranslate("Config","lang","ca","unit",6)="sis" + set ^NumberTranslate("Config","lang","ca","unit",7)="set" + set ^NumberTranslate("Config","lang","ca","unit",8)="vuit" + set ^NumberTranslate("Config","lang","ca","unit",9)="nou" + set ^NumberTranslate("Config","lang","ca","unit",10)="deu" + set ^NumberTranslate("Config","lang","ca","unit",11)="onze" + set ^NumberTranslate("Config","lang","ca","unit",12)="dotze" + set ^NumberTranslate("Config","lang","ca","unit",13)="tretze" + set ^NumberTranslate("Config","lang","ca","unit",14)="catorze" + set ^NumberTranslate("Config","lang","ca","unit",15)="quinze" + set ^NumberTranslate("Config","lang","ca","unit",16)="setze" + set ^NumberTranslate("Config","lang","ca","unit",17)="disset" + set ^NumberTranslate("Config","lang","ca","unit",18)="divuit" + set ^NumberTranslate("Config","lang","ca","unit",19)="dinou" + set ^NumberTranslate("Config","lang","ca","unit",20)="vint-i" + set ^NumberTranslate("Config","lang","ca","unit",21)="trenta" + set ^NumberTranslate("Config","lang","ca","unit",22)="quaranta" + set ^NumberTranslate("Config","lang","ca","unit",23)="cinquanta" + set ^NumberTranslate("Config","lang","ca","unit",24)="seixanta" + set ^NumberTranslate("Config","lang","ca","unit",25)="setanta" + set ^NumberTranslate("Config","lang","ca","unit",26)="vuitanta" + set ^NumberTranslate("Config","lang","ca","unit",27)="noranta" + set ^NumberTranslate("Config","lang","ca","unit",29)="vint" + + // units and tens (en) + set ^NumberTranslate("Config","lang","en","unit",1)="one" + set ^NumberTranslate("Config","lang","en","unit",2)="two" + set ^NumberTranslate("Config","lang","en","unit",3)="three" + set ^NumberTranslate("Config","lang","en","unit",4)="four" + set ^NumberTranslate("Config","lang","en","unit",5)="five" + set ^NumberTranslate("Config","lang","en","unit",6)="six" + set ^NumberTranslate("Config","lang","en","unit",7)="seven" + set ^NumberTranslate("Config","lang","en","unit",8)="eight" + set ^NumberTranslate("Config","lang","en","unit",9)="nine" + set ^NumberTranslate("Config","lang","en","unit",10)="ten" + set ^NumberTranslate("Config","lang","en","unit",11)="eleven" + set ^NumberTranslate("Config","lang","en","unit",12)="twelve" + set ^NumberTranslate("Config","lang","en","unit",13)="thirteen" + set ^NumberTranslate("Config","lang","en","unit",14)="fourteen" + set ^NumberTranslate("Config","lang","en","unit",15)="fiveteen" + set ^NumberTranslate("Config","lang","en","unit",16)="sixteen" + set ^NumberTranslate("Config","lang","en","unit",17)="seventeen" + set ^NumberTranslate("Config","lang","en","unit",18)="eighteen" + set ^NumberTranslate("Config","lang","en","unit",19)="nineteen" + set ^NumberTranslate("Config","lang","en","unit",20)="twenty" + set ^NumberTranslate("Config","lang","en","unit",21)="thirty" + set ^NumberTranslate("Config","lang","en","unit",22)="forty" + set ^NumberTranslate("Config","lang","en","unit",23)="fifty" + set ^NumberTranslate("Config","lang","en","unit",24)="sixty" + set ^NumberTranslate("Config","lang","en","unit",25)="seventy" + set ^NumberTranslate("Config","lang","en","unit",26)="eighty" + set ^NumberTranslate("Config","lang","en","unit",27)="ninety" + set ^NumberTranslate("Config","lang","en","unit",29)="twenty" + + // units and tens (ru) + set ^NumberTranslate("Config","lang","ru","unit",1)="один" + set ^NumberTranslate("Config","lang","ru","unit",2)="два" + set ^NumberTranslate("Config","lang","ru","unit",3)="три" + set ^NumberTranslate("Config","lang","ru","unit",4)="четыре" + set ^NumberTranslate("Config","lang","ru","unit",5)="пять" + set ^NumberTranslate("Config","lang","ru","unit",6)="шесть" + set ^NumberTranslate("Config","lang","ru","unit",7)="семь" + set ^NumberTranslate("Config","lang","ru","unit",8)="восемь" + set ^NumberTranslate("Config","lang","ru","unit",9)="девять" + set ^NumberTranslate("Config","lang","ru","unit",10)="десять" + set ^NumberTranslate("Config","lang","ru","unit",11)="одиннадцать" + set ^NumberTranslate("Config","lang","ru","unit",12)="двенадцать" + set ^NumberTranslate("Config","lang","ru","unit",13)="тринадцать" + set ^NumberTranslate("Config","lang","ru","unit",14)="четырнадцать" + set ^NumberTranslate("Config","lang","ru","unit",15)="пятнадцать" + set ^NumberTranslate("Config","lang","ru","unit",16)="шестнадцать" + set ^NumberTranslate("Config","lang","ru","unit",17)="семнадцать" + set ^NumberTranslate("Config","lang","ru","unit",18)="восемнадцать" + set ^NumberTranslate("Config","lang","ru","unit",19)="девятнадцать" + set ^NumberTranslate("Config","lang","ru","unit",20)="двадцать" + set ^NumberTranslate("Config","lang","ru","unit",21)="тридцать" + set ^NumberTranslate("Config","lang","ru","unit",22)="сорок" + set ^NumberTranslate("Config","lang","ru","unit",23)="пятьдесят" + set ^NumberTranslate("Config","lang","ru","unit",24)="шестьдесят" + set ^NumberTranslate("Config","lang","ru","unit",25)="семьдесят" + set ^NumberTranslate("Config","lang","ru","unit",26)="восемьдесят" + set ^NumberTranslate("Config","lang","ru","unit",27)="девяносто" + set ^NumberTranslate("Config","lang","ru","unit",29)="двадцать" + + // Hundreds (es) + set ^NumberTranslate("Config","lang","es","hundred",0)="cien" + set ^NumberTranslate("Config","lang","es","hundred",1)="ciento" + set ^NumberTranslate("Config","lang","es","hundred",2)="doscientos" + set ^NumberTranslate("Config","lang","es","hundred",3)="trescientos" + set ^NumberTranslate("Config","lang","es","hundred",4)="cuatrocientos" + set ^NumberTranslate("Config","lang","es","hundred",5)="quinientos" + set ^NumberTranslate("Config","lang","es","hundred",6)="seiscientos" + set ^NumberTranslate("Config","lang","es","hundred",7)="setecientos" + set ^NumberTranslate("Config","lang","es","hundred",8)="ochocientos" + set ^NumberTranslate("Config","lang","es","hundred",9)="novecientos" + + // Hundreds (ca) + set ^NumberTranslate("Config","lang","ca","hundred",0)="cent" + set ^NumberTranslate("Config","lang","ca","hundred",1)="cent" + set ^NumberTranslate("Config","lang","ca","hundred",2)="dos-cents" + set ^NumberTranslate("Config","lang","ca","hundred",3)="tres-cents" + set ^NumberTranslate("Config","lang","ca","hundred",4)="quatre-cents" + set ^NumberTranslate("Config","lang","ca","hundred",5)="cinc-cents" + set ^NumberTranslate("Config","lang","ca","hundred",6)="sis-cents" + set ^NumberTranslate("Config","lang","ca","hundred",7)="set-cents" + set ^NumberTranslate("Config","lang","ca","hundred",8)="vuit-cents" + set ^NumberTranslate("Config","lang","ca","hundred",9)="nou-cents" + + // Hundreds (en) + set ^NumberTranslate("Config","lang","en","hundred",0)="one hundred" + set ^NumberTranslate("Config","lang","en","hundred",1)="one hundred" + set ^NumberTranslate("Config","lang","en","hundred",2)="two hundred" + set ^NumberTranslate("Config","lang","en","hundred",3)="three hundred" + set ^NumberTranslate("Config","lang","en","hundred",4)="four hundred" + set ^NumberTranslate("Config","lang","en","hundred",5)="five hundred" + set ^NumberTranslate("Config","lang","en","hundred",6)="six hundred" + set ^NumberTranslate("Config","lang","en","hundred",7)="seven hundred" + set ^NumberTranslate("Config","lang","en","hundred",8)="eight hundred" + set ^NumberTranslate("Config","lang","en","hundred",9)="nine hundred" + + // Hundreds (ru) + set ^NumberTranslate("Config","lang","ru","hundred",0)="Сто" + set ^NumberTranslate("Config","lang","ru","hundred",1)="Сто" + set ^NumberTranslate("Config","lang","ru","hundred",2)="двести" + set ^NumberTranslate("Config","lang","ru","hundred",3)="триста" + set ^NumberTranslate("Config","lang","ru","hundred",4)="четыреста" + set ^NumberTranslate("Config","lang","ru","hundred",5)="пятьсот" + set ^NumberTranslate("Config","lang","ru","hundred",6)="шестьсот" + set ^NumberTranslate("Config","lang","ru","hundred",7)="семьсот" + set ^NumberTranslate("Config","lang","ru","hundred",8)="восемьсот" + set ^NumberTranslate("Config","lang","ru","hundred",9)="девятьсот" +} + +} diff --git a/NumberTranslate/NumberTranslate/NumberTranslate.cls b/NumberTranslate/NumberTranslate/NumberTranslate.cls index fdf6810..e13f226 100644 --- a/NumberTranslate/NumberTranslate/NumberTranslate.cls +++ b/NumberTranslate/NumberTranslate/NumberTranslate.cls @@ -1,353 +1,353 @@ -/// -/// NumberTranslate.NumberTranslate -///

NumberTranslate

-///

Overview

-///

the aim of this function is to convert numbers into text.

-///

It allows a maximum number of 15 digits.

-///

The translation is done in several languages. The allowed languages are

-///

    -///
  • es: Spanish
  • -///
  • en: English
  • -///
  • ca: Catalan
  • -///

-///

The function also allows to treat the numbers of 10^9 (millards) in English-speaking countries format. See the following link Billion Wikipedia

-///

Example

-///
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc)
-/// one hundred and twenty-three
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"es")
-/// ciento veintitres
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"ca")
-/// cent vint-i-tres
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000,.tSc,"en",1)
-/// one billion
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000,.tSc,"en",0)
-/// one thousand millions
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000000,.tSc,"en",1)
-/// one trillion
-/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000000,.tSc,"en",0)
-/// one billion
-/// 
-///

In case of error, you can catch the error with the status variable -///

-/// USER> set text=##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"fr") 
-/// USER> if ('tSc) { w $System.Status.GetErrorText(tSc) } else { w text }        
-/// ERROR #420: Lang fr not exists
-/// 
-/// -Class NumberTranslate.NumberTranslate Extends %RegisteredObject [ Not ProcedureBlock ] -{ - -/// Internal method to get trio of digit and translate according to language -Method Trio(pTrio As %String) As %String -{ - if (^NumberTranslate("Current","debug")) - { - w "--------------",! - w "Value trio:",?25,pTrio,! - } - set lcent = $EXTRACT(pTrio,1,1) - set lten = $EXTRACT(pTrio,2,2) - set lunit = $EXTRACT(pTrio,3,3) - - set lang = ^NumberTranslate("Current","lang") - - set figure = "" - - // First figure (cent) - if (lcent>0) - { - set figure=figure_$SELECT((lcent=1)&&((lten=0)&&(lunit=0)):^NumberTranslate("Config","lang",lang,"hundred",0), - 1:^NumberTranslate("Config","lang",lang,"hundred",lcent)) - } - - if (lcent>0)&&((lten>0)||(lunit>0)) - { - set figure=figure_^NumberTranslate("Config","lang",lang,"concat-cents") - } - - // Second figure (tens) - if ((lten>=3)&&(lten<=9)) - { - set figure = figure_$SELECT(lunit=0:%obj.GetDigit(lten*10)_" ",lunit>0:%obj.GetDigit(lten*10)_^NumberTranslate("Config","lang",lang,"concat-tens")) - } elseif (lten = 2) - { - set figure = figure_$SELECT(lunit=0:^NumberTranslate("Config","lang",lang,"unit",29)_" ",1:%obj.GetDigit(lten*10)) - // Condition only for Spanish and twenty - if (lang'="es")&&(lunit>0) - { - set figure = figure_^NumberTranslate("Config","lang",lang,"concat-tens") - } - } elseif (lten = 1) - { - set figure = figure_" "_%obj.GetDigit((lten*10)+lunit)_" " - } - - // Third figure (unit) - if ((lunit>0)&&(lten'=1)) - { - set figure = figure_%obj.GetDigit(lunit) - } - - - // Remove all double spaces - set figure=$Replace(figure," "," ") - quit figure -} - -/// Internal method to get the text of digit -Method GetDigit(pNumber As %Integer) As %String -{ - set sCurrent = "" - set lang = ^NumberTranslate("Current","lang") - - if (pNumber <= 20) - { - // From 1 to 20 is the same than position of Unit - set sCurrent = ^NumberTranslate("Config","lang",lang,"unit",pNumber) - } - else - { - set lNumber = pNumber - 30 - set lPos = 0 - if (lNumber < 0) - { - set lNumber = lNumber * -1 - set lPos = (lNumber/10) + 21 - } - else - { - if (lNumber = 0) - { - set lPos = 21 - } - else - { - set lPos = (lNumber/10) + 21 - } - } - set sCurrent = ^NumberTranslate("Config","lang",lang,"unit",lPos) - } - - quit sCurrent -} - -/// Translate a number to text -ClassMethod GetText(pNumber As %Decimal, Output pStatus As %Status, pLang As %String = "en", pEngBillion As %Boolean = 0) As %String -{ - quit:pLang="ru" $piece(..RussianMethod(pNumber), " руб") - set %obj=..%New() - set pStatus = $$$OK - set tResult = "" - // Check if code is installed - if ($Get(^NumberTranslate("Config"))'=1) - { - do ##class(NumberTranslate.Initialize).Initialize() - } - - //Allowed langs ^NumberTranslate("Config","lang") - if ('$listfind($LISTFROMSTRING(^NumberTranslate("Config","lang"),";"),pLang)) - { - SET pStatus = $System.Status.Error(420,"Lang",pLang) - Quit tResult - } - - set ^NumberTranslate("Current","lang")=pLang - set ^NumberTranslate("Current","culture")=$CASE(pEngBillion,1:"en",0:"") - - set number = $System.SQL.TOCHAR(pNumber,"000000000000000") - set billion=$Extract(number,0,4) - set millard=$Extract(number,5,7) - set million=$Extract(number,8,10) - set thousand=$Extract(number,11,13) - set cents=$Extract(number,14,16) - - if (^NumberTranslate("Current","debug")) - { - w "Number to process:",?25,number,! - w "(EUR) Billion:",?25,billion,! - w "Millard:",?25,millard,! - w "Million:",?25,million,! - w "Thousand:",?25,thousand,! - w "Cents:",?25,cents,! - } - - // Five blocks, watch out with billion USA and billion EUR - for block=1:1:5 - { - if (block=1) // (EUR) Billion / (ENG) Trillion - { - // Acording to culture, the text could be trillion or billion - set textBlock=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"trillion"),0:^NumberTranslate("Config","lang",pLang,"billion")) - set textBlocks=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"trillions"),0:^NumberTranslate("Config","lang",pLang,"billions")) - - set tResult=tResult_" "_$SELECT($Number(billion)=1:^NumberTranslate("Config","lang",pLang,"unit")_" "_textBlock,$Number(billion)>1:%obj.Trio(billion)_" "_textBlocks,1:"") - } - if (block=2) // (EUR) Thousand million / (ENG) Billion - { - // Acording to culture, the text could be billion or thousand (of billion) - set textBlock=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"billion"),0:^NumberTranslate("Config","lang",pLang,"thousand")) - set textBlocks=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"billions"),0:^NumberTranslate("Config","lang",pLang,"thousand")) - - set tResult=tResult_" "_$SELECT($Number(millard)=1:^NumberTranslate("Config","lang",pLang,"unit")_" "_textBlock, $Number(millard)>1:%obj.Trio(millard)_" "_textBlocks, 1:"") - - } - if (block=3) // Million - { - set textBlock=^NumberTranslate("Config","lang",pLang,"million") - set textBlocks=^NumberTranslate("Config","lang",pLang,"millions") - - set tResult=tResult_" "_$SELECT($Number(million)=1:^NumberTranslate("Config","lang",pLang,"unit")_" "_textBlock, - $Number(million)>1:%obj.Trio(million)_" "_textBlocks, - $Number(millard)>0: $SELECT(pEngBillion=1:" ",1:" "_textBlocks),1:"") - } - if (block=4) // Thousand - { - set textBlock=^NumberTranslate("Config","lang",pLang,"thousand") - // RU: 1000 - тысяча - // 2000 - 4000: тысячи - // 5000 - 9000: тысяч - if (pLang="ru") - { - set textBlock=textBlock_$SELECT($EXTRACT(thousand,3,3)=1:"а",($EXTRACT(thousand,3,3)>1) && ($EXTRACT(thousand,3,3)<5):"и",1:"") - } - - // In RU, ES and CA, just for one thousand, the number is omitted. The rest of language is showed - if (pLang="en") - { - set tResult=tResult_" "_$SELECT($Number(thousand)>0:%obj.Trio(thousand)_" "_textBlock,1:"") - } else - { - set tResult=tResult_" "_$SELECT($Number(thousand)=1:textBlock, $Number(thousand)>1:%obj.Trio(thousand)_" "_textBlock,1:"") - } - } - if (block=5) // Cents - { - set tResult=tResult_" "_%obj.Trio(cents) - } - } - - kill %obj - set tResult = $ZSTRIP($Replace(tResult," "," "),"<>"," ") - Quit tResult -} - -/// Russian Translate -ClassMethod RussianMethod(summa As %Decimal = "") As %String -{ - new SUMMA,SUMMAP,%X,%X0,%X1,R0,R1,VV,V2,V3,V - set SUMMA=summa - I +SUMMA'<1000000000000 S SUMMAP=SUMMA G END0 ;### - I +SUMMA<0 S SUMMA=-SUMMA - S %X=+$P(SUMMA,".",1),SUMMAP="",VV=0 - ;I %X=0 S SUMMAP="ноль рублей" - I %X=0 S SUMMAP="ноль " - I %X>0 D PRUBL - S V2=$E(%X,$L(%X)-1),V3=$E(%X,$L(%X)) - I V3=1,V2'=1 S SUMMAP=SUMMAP_" рубль",VV=1 - I ((V3=2)!(V3=3)!(V3=4))&(V2'=1) S SUMMAP=SUMMAP_" рубля",VV=1 - I ((V3=1)!(V3=2)!(V3=3)!(V3=4))&(V2=1) S SUMMAP=SUMMAP_" рублей",VV=1 - I V3>4 S SUMMAP=SUMMAP_" рублей",VV=1 - I VV=0 S SUMMAP=SUMMAP_" рублей" - S %X=$P(SUMMA,".",2) I %X="" S %X="00" - I %X?1N S %X=%X_"0",(V1,V)="0" - I %X?2N S V1=$E(%X,1,1),V=$E(%X,2,2) -R1 I (V="1")&(V1'="1") S SUMMAP=SUMMAP_" "_%X_" копейка" - I ((V="2")!(V="3")!(V="4"))&(V1'="1") S SUMMAP=SUMMAP_" "_%X_" копейки" - I ((V'="1")&(V'="2")&(V'="3")&(V'="4"))!(V1="1") S SUMMAP=SUMMAP_" "_%X_" копеек" - I $E(SUMMAP)=" " S SUMMAP=$E(SUMMAP,2,255) - S SUMMAP=$TR($E(SUMMAP),"одтчпшсвн","ОДТЧПШСВН")_$E(SUMMAP,2,255) -END0 K %X,%X0,%X1,R0,R1 - Q (SUMMAP) ;1 - ;- -PRUBL ; Euro - D PMILR,PMILE,PtYS,PEDIN - Q ;Added - ;- -PMILR ;BILLION - S %X0=%X\1000000000 Q:%X0=0 ;### - D PSoT,PDES - -RRR3 S SUMMAP=SUMMAP_" миллиард"_$S(%X0#100=0:"ов",%X0#100>10&(%X0#100<21):"ов",%X0#10>1&(%X0#10<5):"а",%X0#10=1:"",1:"ов")_" " - K R3 - Q ;PMILR - ;- -PMILE ;Millions - ;S %X0=%X\1000000 Q:%X0=0 ;### - S %X0=%X#1000000000\1000000 Q:%X0=0 ;### - D PSoT,PDES - -R3 S SUMMAP=SUMMAP_" миллион"_$S(%X0#100=0:"ов",%X0#100>10&(%X0#100<21):"ов",%X0#10>1&(%X0#10<5):"а",%X0#10=1:"",1:"ов")_" " - K R3 - Q ;PMILE - ;- -PtYS ;THOUSAND - S %X0=%X#1000000\1000 Q:%X0=0 ;### - D PSoT,PDES - S %X1=$E(SUMMAP,$L(SUMMAP)-2,$L(SUMMAP)) - I %X1="ва " S SUMMAP=$E(SUMMAP,1,$L(SUMMAP)-3)_"ве " - I %X1="ин " S SUMMAP=$E(SUMMAP,1,$L(SUMMAP)-3)_"на " -QQ S SUMMAP=SUMMAP_"тысяч"_$S(%X0#100=11:"",%X0#100=12:"",%X0#100=13:"",%X0#100=14:"",%X0#10=1:"а",%X0#10>1&(%X0#10<5):"и",1:"")_" " - K R4,R5,R6 - Q ;PtYS - ;- -PEDIN ;UNITS IN BREAKDOWN - S %X0=%X#1000 Q:%X0=0 ;### - D PSoT,PDES - Q ;PtDIN - ;- -PSoT ;HUNDREDS - S %X1=%X0\100 Q:%X1=0 ;### -R7 S S1="сто" -R8 S S2="двести" -R9 S S3="триста" -R10 S S4="четыреста" -R11 S S5="пятьсот" -R12 S S6="шестьсот" -R13 S S7="семьсот" -R14 S S8="восемьсот" -R15 S S9="девятьсот" - S SUMMAP=SUMMAP_$S(%X1=1:S1,%X1=2:S2,%X1=3:S3,%X1=4:S4,%X1=5:S5,%X1=6:S6,%X1=7:S7,%X1=8:S8,%X1=9:S9)_" " - K S1,S2,S3,S4,S5,S6,S7,S8,S9 - Q ;PSoT - ;- -PDES ;TENS - S %X1=%X0#100\10 Q:%X=0 ;### - I %X1=1 D PDC Q ;### -R17 S D2="двадцать" -R18 S D3="тридцать" -R19 S D4="сорок" -R20 S D5="пятьдесят" -R21 S D6="шестьдесят" -R22 S D7="семьдесят" -R23 S D8="восемьдесят" -R24 S D9="девяносто" - S SUMMAP=SUMMAP_$S(%X1=2:D2,%X1=3:D3,%X1=4:D4,%X1=5:D5,%X1=6:D6,%X1=7:D7,%X1=8:D8,%X1=9:D9,1:"")_" " - K D2,D3,D4,D5,D6,D7,D8,D9 - D PoDIN - Q ;PDES - ;- -PDC ; - S %X1=%X0#10 -R25 S F0="десять" -R26 S F1="одиннадцать" -R27 S F2="двенадцать" -R28 S F3="тринадцать" -R29 S F4="четырнадцать" -R30 S F5="пятнадцать" -R31 S F6="шестнадцать" -R32 S F7="семнадцать" -R33 S F8="восемнадцать" -R34 S F9="девятнадцать" - S SUMMAP=SUMMAP_$S(%X1=0:F0,%X1=1:F1,%X1=2:F2,%X1=3:F3,%X1=4:F4,%X1=5:F5,%X1=6:F6,%X1=7:F7,%X1=8:F8,%X1=9:F9) - K F0,F1,F2,F3,F4,F5,F6,F7,F8,F9 - Q ;PDC - ;- -PoDIN ;UNITS - S %X1=%X0#10 I %X1=0 Q ;### - S SUMMAP=SUMMAP_$S(%X1=1:"один",%X1=2:"два",%X1=3:"три",%X1=4:"четыре",%X1=5:"пять",%X1=6:"шесть",%X1=7:"семь",%X1=8:"восемь",%X1=9:"девять",1:"")_" " - K E1,E2,E3,E4,E5,E6,E7,E8,E9 - Q ;PoDIN -} - -} +/// +/// NumberTranslate.NumberTranslate +///

NumberTranslate

+///

Overview

+///

the aim of this function is to convert numbers into text.

+///

It allows a maximum number of 15 digits.

+///

The translation is done in several languages. The allowed languages are

+///

    +///
  • es: Spanish
  • +///
  • en: English
  • +///
  • ca: Catalan
  • +///

+///

The function also allows to treat the numbers of 10^9 (millards) in English-speaking countries format. See the following link Billion Wikipedia

+///

Example

+///
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc)
+/// one hundred and twenty-three
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"es")
+/// ciento veintitres
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"ca")
+/// cent vint-i-tres
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000,.tSc,"en",1)
+/// one billion
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000,.tSc,"en",0)
+/// one thousand millions
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000000,.tSc,"en",1)
+/// one trillion
+/// USER> w ##class(NumberTranslate.NumberTranslate).GetText(1000000000000,.tSc,"en",0)
+/// one billion
+/// 
+///

In case of error, you can catch the error with the status variable +///

+/// USER> set text=##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"fr") 
+/// USER> if ('tSc) { w $System.Status.GetErrorText(tSc) } else { w text }        
+/// ERROR #420: Lang fr not exists
+/// 
+/// +Class NumberTranslate.NumberTranslate Extends %RegisteredObject [ Not ProcedureBlock ] +{ + +/// Internal method to get trio of digit and translate according to language +Method Trio(pTrio As %String) As %String +{ + if (^NumberTranslate("Current","debug")) + { + w "--------------",! + w "Value trio:",?25,pTrio,! + } + set lcent = $EXTRACT(pTrio,1,1) + set lten = $EXTRACT(pTrio,2,2) + set lunit = $EXTRACT(pTrio,3,3) + + set lang = ^NumberTranslate("Current","lang") + + set figure = "" + + // First figure (cent) + if (lcent>0) + { + set figure=figure_$SELECT((lcent=1)&&((lten=0)&&(lunit=0)):^NumberTranslate("Config","lang",lang,"hundred",0), + 1:^NumberTranslate("Config","lang",lang,"hundred",lcent)) + } + + if (lcent>0)&&((lten>0)||(lunit>0)) + { + set figure=figure_^NumberTranslate("Config","lang",lang,"concat-cents") + } + + // Second figure (tens) + if ((lten>=3)&&(lten<=9)) + { + set figure = figure_$SELECT(lunit=0:%obj.GetDigit(lten*10)_" ",lunit>0:%obj.GetDigit(lten*10)_^NumberTranslate("Config","lang",lang,"concat-tens")) + } elseif (lten = 2) + { + set figure = figure_$SELECT(lunit=0:^NumberTranslate("Config","lang",lang,"unit",29)_" ",1:%obj.GetDigit(lten*10)) + // Condition only for Spanish and twenty + if (lang'="es")&&(lunit>0) + { + set figure = figure_^NumberTranslate("Config","lang",lang,"concat-tens") + } + } elseif (lten = 1) + { + set figure = figure_" "_%obj.GetDigit((lten*10)+lunit)_" " + } + + // Third figure (unit) + if ((lunit>0)&&(lten'=1)) + { + set figure = figure_%obj.GetDigit(lunit) + } + + + // Remove all double spaces + set figure=$Replace(figure," "," ") + quit figure +} + +/// Internal method to get the text of digit +Method GetDigit(pNumber As %Integer) As %String +{ + set sCurrent = "" + set lang = ^NumberTranslate("Current","lang") + + if (pNumber <= 20) + { + // From 1 to 20 is the same than position of Unit + set sCurrent = ^NumberTranslate("Config","lang",lang,"unit",pNumber) + } + else + { + set lNumber = pNumber - 30 + set lPos = 0 + if (lNumber < 0) + { + set lNumber = lNumber * -1 + set lPos = (lNumber/10) + 21 + } + else + { + if (lNumber = 0) + { + set lPos = 21 + } + else + { + set lPos = (lNumber/10) + 21 + } + } + set sCurrent = ^NumberTranslate("Config","lang",lang,"unit",lPos) + } + + quit sCurrent +} + +/// Translate a number to text +ClassMethod GetText(pNumber As %Decimal, Output pStatus As %Status, pLang As %String = "en", pEngBillion As %Boolean = 0) As %String +{ + quit:pLang="ru" $piece(..RussianMethod(pNumber), " руб") + set %obj=..%New() + set pStatus = $$$OK + set tResult = "" + // Check if code is installed + if ($Get(^NumberTranslate("Config"))'=1) + { + do ##class(NumberTranslate.Initialize).Initialize() + } + + //Allowed langs ^NumberTranslate("Config","lang") + if ('$listfind($LISTFROMSTRING(^NumberTranslate("Config","lang"),";"),pLang)) + { + SET pStatus = $System.Status.Error(420,"Lang",pLang) + Quit tResult + } + + set ^NumberTranslate("Current","lang")=pLang + set ^NumberTranslate("Current","culture")=$CASE(pEngBillion,1:"en",0:"") + + set number = $System.SQL.TOCHAR(pNumber,"000000000000000") + set billion=$Extract(number,0,4) + set millard=$Extract(number,5,7) + set million=$Extract(number,8,10) + set thousand=$Extract(number,11,13) + set cents=$Extract(number,14,16) + + if (^NumberTranslate("Current","debug")) + { + w "Number to process:",?25,number,! + w "(EUR) Billion:",?25,billion,! + w "Millard:",?25,millard,! + w "Million:",?25,million,! + w "Thousand:",?25,thousand,! + w "Cents:",?25,cents,! + } + + // Five blocks, watch out with billion USA and billion EUR + for block=1:1:5 + { + if (block=1) // (EUR) Billion / (ENG) Trillion + { + // Acording to culture, the text could be trillion or billion + set textBlock=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"trillion"),0:^NumberTranslate("Config","lang",pLang,"billion")) + set textBlocks=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"trillions"),0:^NumberTranslate("Config","lang",pLang,"billions")) + + set tResult=tResult_" "_$SELECT($Number(billion)=1:^NumberTranslate("Config","lang",pLang,"unit")_" "_textBlock,$Number(billion)>1:%obj.Trio(billion)_" "_textBlocks,1:"") + } + if (block=2) // (EUR) Thousand million / (ENG) Billion + { + // Acording to culture, the text could be billion or thousand (of billion) + set textBlock=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"billion"),0:^NumberTranslate("Config","lang",pLang,"thousand")) + set textBlocks=$CASE(pEngBillion,1:^NumberTranslate("Config","lang",pLang,"billions"),0:^NumberTranslate("Config","lang",pLang,"thousand")) + + set tResult=tResult_" "_$SELECT($Number(millard)=1:^NumberTranslate("Config","lang",pLang,"unit")_" "_textBlock, $Number(millard)>1:%obj.Trio(millard)_" "_textBlocks, 1:"") + + } + if (block=3) // Million + { + set textBlock=^NumberTranslate("Config","lang",pLang,"million") + set textBlocks=^NumberTranslate("Config","lang",pLang,"millions") + + set tResult=tResult_" "_$SELECT($Number(million)=1:^NumberTranslate("Config","lang",pLang,"unit")_" "_textBlock, + $Number(million)>1:%obj.Trio(million)_" "_textBlocks, + $Number(millard)>0: $SELECT(pEngBillion=1:" ",1:" "_textBlocks),1:"") + } + if (block=4) // Thousand + { + set textBlock=^NumberTranslate("Config","lang",pLang,"thousand") + // RU: 1000 - тысяча + // 2000 - 4000: тысячи + // 5000 - 9000: тысяч + if (pLang="ru") + { + set textBlock=textBlock_$SELECT($EXTRACT(thousand,3,3)=1:"а",($EXTRACT(thousand,3,3)>1) && ($EXTRACT(thousand,3,3)<5):"и",1:"") + } + + // In RU, ES and CA, just for one thousand, the number is omitted. The rest of language is showed + if (pLang="en") + { + set tResult=tResult_" "_$SELECT($Number(thousand)>0:%obj.Trio(thousand)_" "_textBlock,1:"") + } else + { + set tResult=tResult_" "_$SELECT($Number(thousand)=1:textBlock, $Number(thousand)>1:%obj.Trio(thousand)_" "_textBlock,1:"") + } + } + if (block=5) // Cents + { + set tResult=tResult_" "_%obj.Trio(cents) + } + } + + kill %obj + set tResult = $ZSTRIP($Replace(tResult," "," "),"<>"," ") + Quit tResult +} + +/// Russian Translate +ClassMethod RussianMethod(summa As %Decimal = "") As %String +{ + new SUMMA,SUMMAP,%X,%X0,%X1,R0,R1,VV,V2,V3,V + set SUMMA=summa + I +SUMMA'<1000000000000 S SUMMAP=SUMMA G END0 ;### + I +SUMMA<0 S SUMMA=-SUMMA + S %X=+$P(SUMMA,".",1),SUMMAP="",VV=0 + ;I %X=0 S SUMMAP="ноль рублей" + I %X=0 S SUMMAP="ноль " + I %X>0 D PRUBL + S V2=$E(%X,$L(%X)-1),V3=$E(%X,$L(%X)) + I V3=1,V2'=1 S SUMMAP=SUMMAP_" рубль",VV=1 + I ((V3=2)!(V3=3)!(V3=4))&(V2'=1) S SUMMAP=SUMMAP_" рубля",VV=1 + I ((V3=1)!(V3=2)!(V3=3)!(V3=4))&(V2=1) S SUMMAP=SUMMAP_" рублей",VV=1 + I V3>4 S SUMMAP=SUMMAP_" рублей",VV=1 + I VV=0 S SUMMAP=SUMMAP_" рублей" + S %X=$P(SUMMA,".",2) I %X="" S %X="00" + I %X?1N S %X=%X_"0",(V1,V)="0" + I %X?2N S V1=$E(%X,1,1),V=$E(%X,2,2) +R1 I (V="1")&(V1'="1") S SUMMAP=SUMMAP_" "_%X_" копейка" + I ((V="2")!(V="3")!(V="4"))&(V1'="1") S SUMMAP=SUMMAP_" "_%X_" копейки" + I ((V'="1")&(V'="2")&(V'="3")&(V'="4"))!(V1="1") S SUMMAP=SUMMAP_" "_%X_" копеек" + I $E(SUMMAP)=" " S SUMMAP=$E(SUMMAP,2,255) + S SUMMAP=$TR($E(SUMMAP),"одтчпшсвн","ОДТЧПШСВН")_$E(SUMMAP,2,255) +END0 K %X,%X0,%X1,R0,R1 + Q (SUMMAP) ;1 + ;- +PRUBL ; Euro + D PMILR,PMILE,PtYS,PEDIN + Q ;Added + ;- +PMILR ;BILLION + S %X0=%X\1000000000 Q:%X0=0 ;### + D PSoT,PDES + +RRR3 S SUMMAP=SUMMAP_" миллиард"_$S(%X0#100=0:"ов",%X0#100>10&(%X0#100<21):"ов",%X0#10>1&(%X0#10<5):"а",%X0#10=1:"",1:"ов")_" " + K R3 + Q ;PMILR + ;- +PMILE ;Millions + ;S %X0=%X\1000000 Q:%X0=0 ;### + S %X0=%X#1000000000\1000000 Q:%X0=0 ;### + D PSoT,PDES + +R3 S SUMMAP=SUMMAP_" миллион"_$S(%X0#100=0:"ов",%X0#100>10&(%X0#100<21):"ов",%X0#10>1&(%X0#10<5):"а",%X0#10=1:"",1:"ов")_" " + K R3 + Q ;PMILE + ;- +PtYS ;THOUSAND + S %X0=%X#1000000\1000 Q:%X0=0 ;### + D PSoT,PDES + S %X1=$E(SUMMAP,$L(SUMMAP)-2,$L(SUMMAP)) + I %X1="ва " S SUMMAP=$E(SUMMAP,1,$L(SUMMAP)-3)_"ве " + I %X1="ин " S SUMMAP=$E(SUMMAP,1,$L(SUMMAP)-3)_"на " +QQ S SUMMAP=SUMMAP_"тысяч"_$S(%X0#100=11:"",%X0#100=12:"",%X0#100=13:"",%X0#100=14:"",%X0#10=1:"а",%X0#10>1&(%X0#10<5):"и",1:"")_" " + K R4,R5,R6 + Q ;PtYS + ;- +PEDIN ;UNITS IN BREAKDOWN + S %X0=%X#1000 Q:%X0=0 ;### + D PSoT,PDES + Q ;PtDIN + ;- +PSoT ;HUNDREDS + S %X1=%X0\100 Q:%X1=0 ;### +R7 S S1="сто" +R8 S S2="двести" +R9 S S3="триста" +R10 S S4="четыреста" +R11 S S5="пятьсот" +R12 S S6="шестьсот" +R13 S S7="семьсот" +R14 S S8="восемьсот" +R15 S S9="девятьсот" + S SUMMAP=SUMMAP_$S(%X1=1:S1,%X1=2:S2,%X1=3:S3,%X1=4:S4,%X1=5:S5,%X1=6:S6,%X1=7:S7,%X1=8:S8,%X1=9:S9)_" " + K S1,S2,S3,S4,S5,S6,S7,S8,S9 + Q ;PSoT + ;- +PDES ;TENS + S %X1=%X0#100\10 Q:%X=0 ;### + I %X1=1 D PDC Q ;### +R17 S D2="двадцать" +R18 S D3="тридцать" +R19 S D4="сорок" +R20 S D5="пятьдесят" +R21 S D6="шестьдесят" +R22 S D7="семьдесят" +R23 S D8="восемьдесят" +R24 S D9="девяносто" + S SUMMAP=SUMMAP_$S(%X1=2:D2,%X1=3:D3,%X1=4:D4,%X1=5:D5,%X1=6:D6,%X1=7:D7,%X1=8:D8,%X1=9:D9,1:"")_" " + K D2,D3,D4,D5,D6,D7,D8,D9 + D PoDIN + Q ;PDES + ;- +PDC ; + S %X1=%X0#10 +R25 S F0="десять" +R26 S F1="одиннадцать" +R27 S F2="двенадцать" +R28 S F3="тринадцать" +R29 S F4="четырнадцать" +R30 S F5="пятнадцать" +R31 S F6="шестнадцать" +R32 S F7="семнадцать" +R33 S F8="восемнадцать" +R34 S F9="девятнадцать" + S SUMMAP=SUMMAP_$S(%X1=0:F0,%X1=1:F1,%X1=2:F2,%X1=3:F3,%X1=4:F4,%X1=5:F5,%X1=6:F6,%X1=7:F7,%X1=8:F8,%X1=9:F9) + K F0,F1,F2,F3,F4,F5,F6,F7,F8,F9 + Q ;PDC + ;- +PoDIN ;UNITS + S %X1=%X0#10 I %X1=0 Q ;### + S SUMMAP=SUMMAP_$S(%X1=1:"один",%X1=2:"два",%X1=3:"три",%X1=4:"четыре",%X1=5:"пять",%X1=6:"шесть",%X1=7:"семь",%X1=8:"восемь",%X1=9:"девять",1:"")_" " + K E1,E2,E3,E4,E5,E6,E7,E8,E9 + Q ;PoDIN +} + +} diff --git a/README.md b/README.md index 3194131..3befeb6 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,36 @@ ERROR #420: Lang fr not exists 2018-08-07 [Version 1.1](https://github.com/KurroLopez/CosNumberTranslate/blob/master/Version/CosNumberTranslation_v1.1.xml) - Russian translate 2018-06-29 [Version 1.0](https://github.com/KurroLopez/CosNumberTranslate/blob/master/Version/CosNumberTranslation_v1.0.xml) - Initial version + +## Docker +Container build and start runs ALL installation steps. +It is immedeatly ready for use as decsribed +example.script provides quick check from terminal + +### Prerequisites +Make sure you have [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Docker desktop](https://www.docker.com/products/docker-desktop) installed. +### Installation +Clone/git pull the repo into any local directory +``` +$ git clone https://github.com/rcemper/PR_CosNumberTranslate.git +``` +``` +$ docker compose up -d && docker compose logs -f +``` +Quick REST access to MASTER: +http://localhost:42773/synchmaster/rest/v1/customers + +Quick REST access to CLIENT: +http://localhost:42773/synchclient/rest/v1/employees + + +To open IRIS Terminal do: +``` +$ docker-compose exec iris iris session iris +USER> +``` +or using **WebTerminal** +http://localhost:42773/terminal/ + +To access IRIS System Management Portal +http://localhost:42773/csp/sys/UtilHome.csp diff --git a/ascript.sh b/ascript.sh new file mode 100644 index 0000000..7f0f074 --- /dev/null +++ b/ascript.sh @@ -0,0 +1,4 @@ +cd /home/irisowner/dev +iris view +iris session iris < iris.script +exit 0 \ No newline at end of file diff --git a/demo.script b/demo.script new file mode 100644 index 0000000..7e8474f --- /dev/null +++ b/demo.script @@ -0,0 +1,17 @@ +write ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc) +;; one hundred and twenty-three +write ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"es") +;; ciento veintitres +write ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"ca") +;; cent vint-i-tres +write ##class(NumberTranslate.NumberTranslate).GetText(123,.tSc,"ru") +;; Сто двадцать три +write ##class(NumberTranslate.NumberTranslate).GetText(1000000000,.tSc,"en",1) +;; one billion +write ##class(NumberTranslate.NumberTranslate).GetText(1000000000,.tSc,"en",0) +;; one thousand millions +write ##class(NumberTranslate.NumberTranslate).GetText(1000000000000,.tSc,"en",1) +;; one trillion +write ##class(NumberTranslate.NumberTranslate).GetText(1000000000000,.tSc,"en",0) +;; one billion +write diff --git a/dev.md b/dev.md new file mode 100644 index 0000000..080011f --- /dev/null +++ b/dev.md @@ -0,0 +1,117 @@ +# useful commands +## clean up docker +use it when docker says "There is no space left on device". It will remove built but not used images and other temporary files. +``` +docker system prune -f +``` + +``` +docker rm -f $(docker ps -qa) +``` + +## build container with no cache +``` +docker-compose build --no-cache --progress=plain +``` +## start iris container +``` +docker-compose up -d +``` + +## open iris terminal in docker +``` +docker exec iris iris session iris -U IRISAPP +``` + + +## import objectscirpt code + +do $System.OBJ.LoadDir("/home/irisowner/dev/src","ck",,1) +## map iris key from Mac home directory to IRIS in container +- ~/iris.key:/usr/irissys/mgr/iris.key + +## install git in the docker image +## add git in dockerfile +USER root +RUN apt update && apt-get -y install git + +USER ${ISC_PACKAGE_MGRUSER} + + +## install docker-compose +``` +sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + +sudo chmod +x /usr/local/bin/docker-compose + +``` + +## load and test module +``` + +zpm "load /home/irisowner/dev" + +zpm "test dc-sample" +``` + +## select zpm test registry +``` +repo -n registry -r -url https://test.pm.community.intersystems.com/registry/ -user test -pass PassWord42 +``` + +## get back to public zpm registry +``` +repo -r -n registry -url https://pm.community.intersystems.com/ -user "" -pass "" +``` + +## export a global in runtime into the repo +``` +d $System.OBJ.Export("GlobalD.GBL","/irisrun/repo/src/gbl/GlobalD.xml") +``` + +## create a web app in dockerfile +``` +zn "%SYS" \ + write "Create web application ...",! \ + set webName = "/csp/irisweb" \ + set webProperties("NameSpace") = "IRISAPP" \ + set webProperties("Enabled") = 1 \ + set webProperties("CSPZENEnabled") = 1 \ + set webProperties("AutheEnabled") = 32 \ + set webProperties("iKnowEnabled") = 1 \ + set webProperties("DeepSeeEnabled") = 1 \ + set sc = ##class(Security.Applications).Create(webName, .webProperties) \ + write "Web application "_webName_" has been created!",! +``` + + + +``` +do $SYSTEM.OBJ.ImportDir("/opt/irisbuild/src",, "ck") +``` + + +### run tests described in the module + +IRISAPP>zpm +IRISAPP:zpm>load /irisrun/repo +IRISAPP:zpm>test package-name + +### install ZPM with one line + // Install ZPM + set $namespace="%SYS", name="DefaultSSL" do:'##class(Security.SSLConfigs).Exists(name) ##class(Security.SSLConfigs).Create(name) set url="https://pm.community.intersystems.com/packages/zpm/latest/installer" Do ##class(%Net.URLParser).Parse(url,.comp) set ht = ##class(%Net.HttpRequest).%New(), ht.Server = comp("host"), ht.Port = 443, ht.Https=1, ht.SSLConfiguration=name, st=ht.Get(comp("path")) quit:'st $System.Status.GetErrorText(st) set xml=##class(%File).TempFilename("xml"), tFile = ##class(%Stream.FileBinary).%New(), tFile.Filename = xml do tFile.CopyFromAndSave(ht.HttpResponse.Data) do ht.%Close(), $system.OBJ.Load(xml,"ck") do ##class(%File).Delete(xml) + + + + +docker run --rm --name iris-sql -d -p 9091:1972 -p 9092:52773  -e IRIS_PASSWORD=demo -e IRIS_USERNAME=demo intersystemsdc/iris-community + + +docker run --rm --name iris-ce -d -p 9091:1972 -p 9092:52773 -e IRIS_PASSWORD=demo -e IRIS_USERNAME=demo intersystemsdc/iris-community -a "echo 'zpm \"install webterminal\"' | iriscli" + + + +docker run --rm --name iris-sql -d -p 9092:52773 containers.intersystems.com/intersystems/iris-community:2023.1.0.229.0 + + +docker run --rm --name iris-ce -d -p 9092:52773 containers.intersystems.com/intersystems/iris-community:2023.1.0.229.0 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..eea062d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.6' +services: + iris: + image: intersystemsdc/iris-community + restart: always + command: -a /home/irisowner/dev/ascript.sh + + ports: + - 41773:1972 + - 42773:52773 + volumes: + - ./:/home/irisowner/dev diff --git a/iris.script b/iris.script new file mode 100644 index 0000000..1820561 --- /dev/null +++ b/iris.script @@ -0,0 +1,17 @@ + zn "%SYS" + + // Unexpire passwords and set up passwordless mode to simplify dev use. + do ##class(Security.Users).UnExpireUserPasswords("*") + zpm "install passwordless" + + zn "USER" + // Create /_vscode web app to support intersystems-community.testingmanager VS Code extension + zpm "install vscode-per-namespace-settings" + zpm "install webterminal" + + // this should be the place for individual application code. + + do $system.OBJ.Load("/home/irisowner/dev/Version/CosNumberTranslation_v1.1.2.xml","ck") + zpm "list" + halt +