TOKYO -- In roughly three decades, the number of foreign residents in Japan has grown to 2.47 million, from just 980,000 in 1989. So while this period will go down in history as the time the country's population went into decline, it has also brought an unprecedented influx of newcomers from abroad.

Tagalog, Portuguese, Spanish, Thai, Indonesian: The students at Keiwa Elementary School in the southwestern prefecture of Mie speak nine different languages at home. But at school they use Japanese.

"This is how you draw an equilateral pentagon," one non-Japanese sixth-grader said nonchalantly in February. "Can you pass me a protractor?" asked another. Their fluent Japanese had no detectable accent.

Nearly half the school's 250 students belong to at least one non-Japanese parent, making the school a microcosm of rural Japan's new diversity.

The subject of Japanese demographics calls to mind an aging society, a falling birthrate, population decline and rural decay. And yet, under the radar, the increase in immigration has been changing pockets of the country, energizing smaller municipalities that were desperate for labor and tax revenue.

There was a time when Keiwa Elementary's student body had dwindled to just one-seventh of its peak. But thanks partly to a rise in the number of foreign residents working in the nearby Chukyo industrial area, its classrooms are buzzing again.

Kevin Sahayan, a student from the Philippines, said he started learning Japanese when he enrolled in third grade, upon his arrival in the country. "Now that I have learned Japanese, I have more friends and I have fun playing soccer after school," the 12-year-old said.

"Guess which nationality I am!" children asked as, one after another, they pulled the sleeve of this puzzled reporter.

"You probably won't get it so I will tell you. I'm half-Filipina and half-Japanese. That girl over there is Japanese, and that one there ...," explained student Ai Maruyama. Asked whether she feels "different" in the environment, she said, "No, not at all."

In Mie, overall, the number of non-Japanese newcomers more than offset that of residents who moved to Tokyo last year -- 5,999 versus 5,907.

Year after year, more than 100,000 Japanese relocate to Tokyo. © Reuters

This is no small point, considering that the government is struggling to stop the hollowing out of regional industry. Nationwide, around 120,000 people relocated to the Tokyo area in 2017, mainly for education or work, according to the internal affairs ministry. It was the fourth straight year in which the figure topped 100,000, even though the government aims to reduce it to zero by 2020.

But in Gifu and Shiga prefectures, which are adjacent to Mie, increases in residents from abroad made up for 80% of departures in 2017.

In Gifu, local housing company Sunshow Industry has been helping non-Japanese residents purchase homes for five years. Its office in the city of Kani has a sign at the entrance in Portuguese, inviting passers-by to come in for a consultation. Twenty-percent of its customers are foreign nationals.

One Sunday in February, a Brazilian man came in, looking for a house that would be big enough for his family. "I have kids aged 20 and 18, so I want a house where we can have lots of breathing space," said the 43-year-old crane operator, who has lived in Japan for about two decades.

Five years ago, if a Latin American tried to settle in their neighborhood, there would be many residents who would protest it Toshiyuki Shiraki of housing company Sunshow

Sunshow started catering to international residents, mainly from Latin America, as more and more came to work at a Sony subsidiary's plant in the city of Minokamo. Unlike the kids at Keiwa Elementary, though, adults are not always so quick to overlook differences.

"Five years ago, if a Latin American tried to settle in their neighborhood, there would be many residents who would protest it," said Toshiyuki Shiraki, who finds land for Sunshow. In some cases, the hostility persisted even after international workers moved in. A major point of contention was seemingly minor: some newcomers' failure to separate their trash in accordance with the rules.

But Shiraki said the tensions appear to have largely subsided, after a greater effort was made to explain the local ways. Now, Japanese residents seem less averse to sharing their neighborhoods.

Even now, foreign residents make up only about 2% of Japan's population of 127 million, but in certain places the ratio is quite a bit higher. It exceeds 5% in 31 municipalities; the town of Oizumi, in Gunma Prefecture, had the highest share of 17% as of January.

Three municipalities, including Tokyo's Shinjuku Ward and the northern village of Shimukappu in Hokkaido, had ratios over 10%.

Other communities have taken notice of how foreign residents offer vital manpower for companies and more tax revenue for local governments. Some are actively courting immigrants.

The Hokkaido town of Higashikawa set up a Japanese language school to encourage young foreign residents to come, particularly those from other parts of Asia, like Taiwan. This is the first school of its kind run by a Japanese municipality.

The city of Mimasaka, in the western prefecture of Okayama, plans to open a sister school of Vietnam's University of Danang.

Foreign nationals tend to gravitate to places where their children are likely to receive better education. Mie -- home to Keiwa Elementary -- is a testament to this. The prefecture is gaining a reputation for supporting students born to non-Japanese parents. "Mieko san no Nihongo," a textbook for teaching classroom Japanese developed by the Mie International Exchange Foundation, has proved useful in this regard and is now used in elementary and junior high schools nationwide.

According to the Ministry of Education, the number of students requiring additional instruction in the Japanese language at public elementary and junior high schools topped 30,000 for the first time in the year ended March 2017.

The central government, too, is looking to bring more foreign workers into the country. Prime Minister Shinzo Abe last month said his government will design a reform plan for this purpose by the summer. Yet Abe is not exactly jumping in with both feet -- the policy will not encourage permanent settlement, with a cap to be placed on the maximum stay and restrictions on bringing family members along.

Even so, Japan is far more diverse than it was in 1950, when there were only 600,000 residents from overseas. From large cities to tiny villages, Japanese grow ever more accustomed to mingling with their fellow global citizens. And the newcomers are breathing life into communities that looked destined to fade.