A writer who penned a story about a gay migrant has spoken out after a censored copy of the work landed on a Kenyan school syllabus.

Irish author Barry McKinley penned 2016 short story ‘Almost Home,’ which tells the story of Ali Mahfouz, a 17-year-old gay illegal immigrant facing deportation to Morocco, where homosexuality is illegal.

The story recalls the teen’s fear of being sent back to a place where “they caught me in bed with another boy” who was “beaten with steel rods,” and his despair at being removed from Dublin, where he frequented the city’s George’s Street gay district.

A while after first releasing the story, McKinley was baffled to see it getting a lot of interest from young people in Nairobi, Mombasa and Kisumu.

The author decided to investigate the surge in readers – discovering that the story had been reprinted without his permission in an anthology of short stories used by secondary schools across Kenya

Writing in the Irish Times, McKinley explained that the story had been altered by Kenyan education publisher Moran to omit the references to the character’s sexuality.

He wrote: “In Kenya, same-sex relationships can lead to 14 years’ imprisonment… so I wasn’t surprised to find that my principal character, Ali Mafouz, had been de-sexed.”

McKinley says that removing the context of Ali’s sexuality from the work mangles his main message, adding: “His deportation from Ireland to Morocco no longer carried any weight.

“On the Kenyan websites where Ali’s situation is discussed he is described as ‘hardworking,’ ‘stubborn’, ‘charming’ and ‘disillusioned.’ Nowhere is he ever described as ‘gay.'”

Questions in the Kenya Institute of Curriculum Development-approved textbook even ask learners to speculate about why Ali “decided to migrate to Ireland” and what kept him from returning to Morocco.

The author decided to fight back by posting the full, uncensored version of the story online on his website, where, to this day, it is read by inquisitive students who sense something fishy about the censored version.

He added: “I have a substantial number of young Kenyans visit my website every day… and read the uncensored version of ‘Almost Home.'”

Homosexuality is illegal in Kenya, with the law specifying that gay sex can be punished with between 5 to 14 years’ of imprisonment.

A court in the county recently ruled that the use of much-discredited anal probes to ‘test’ for homosexuality is illegal.

The exams are widely discredited internationally, and LGBT activists consider them a form of torture and sexual assault.

Officials behind the exams act based on the mistaken beliefs that every gay man is a receptive partner in anal sex, and that it is possible to identify homosexuals simply through examining their anus. There is no medical evidence to support either supposition.

The National Gay and Lesbian Human Rights Commission (NGLHRC) challenged the practice and successfully convinced a court to rule the practises illegal.

The group said: “We are thankful that the Appeal Court has put Kenyan citizens’ rights first. With this ruling, the judges are saying that we all deserve to be treated with dignity and afforded our basic rights, as enshrined in the Kenyan Constitution.

“The humiliation and pain caused by these useless anal examinations will follow our clients for the rest of their lives. However, we are emboldened to see our constitution at work, ensuring that all Kenyans have the right to dignity.”

The decision came after the Kenya Medical Association (KMA) spoke out against the practice, saying: “Condemn and discourage any form of forced examination of clients, even in the guise of discovering crimes.”

Meanwhile the Kenyan High Court is hearing a challenge to the country’s ban on gay sex.

The case, which was first filed in 2016, aims to challenge the discriminatory sections Kenyan Penal Code that criminalise same-sex relations between adults.

The NGLHRC argues against the sections of the Kenyan Penal Code that criminalise consensual same sex relations between adults – and will await a group of the highest judges in the country to make a decision on the decriminalisation of homosexuality.